Search code examples
gitversion-controlgit-stash

Use git stash apply to reach recent head commit


I worked in the branch master and HEAD points to commit 1.

During my work time, my colleague has pushed his commit with number 2 into the master branch. And now the HEAD points to commit 2.

After commit of my colleague, I want to update the pushes of my colleague into my current working directory. But I have still my own local changes in my working directory.

In this case I put firstly my local change into local stash. And then I pull my local working directory in recent head commit 2.

So my question now, how can I apply the changes in stash to current HEAD commit 2?

If I use git stash apply or git stash add, I will go to the old state based with 0001. I don't want this. I want to push my local changes into the recent commit 2.

My thought here is, maybe I can use somehow cherry pick?


Solution

  • When you stash changes you can apply them later at any point. It work analogical to a merge, wich applies changes to your working directory. If you have conflicting changes you can resolve them in the same way as merge conflicts.