0

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?

LinFelix
  • 1,026
  • 1
  • 13
  • 23
Jia Mu
  • 29
  • 1
  • 6
  • 2
    `git stash apply` should work if there's no conflict. – ElpieKay Jan 18 '18 at 11:20
  • 1
    To continue on the above comment, `git stash` is just a commit (actually, 2 commits, or sometimes even 3), and when you apply a stash, you're just applying a diff on top of wherever you are. – Tim Biegeleisen Jan 18 '18 at 11:21
  • So that means, after stashing and update in recent head commit 0002 using pull, if i use git stash apply, git will put my local changes saved in stash into recent commit 0002? Not the past state local changes with base version 0001? – Jia Mu Jan 18 '18 at 11:48
  • 1
    Stash apply would only apply the patch. Just do `git stash apply` and resolve the conflicts. You won't lose any of your colleague's work. – hspandher Jan 18 '18 at 13:01

1 Answers1

1

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.

LinFelix
  • 1,026
  • 1
  • 13
  • 23