2

Let's say I perform the following commands to create a merge conflict with a git stash pop:

echo "1" > one;
echo "2" > two;
git add -A; 
git commit -m "first";
echo "1.1" > one;
echo "2.1" > two;
git stash;
echo "2.2" > two;
git commit -a -m "second"; 
echo "3" > three;
git add -A;
echo "4" > four;
git stash pop; 
git status

which gives me:

On branch develop
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   one
    new file:   three

Unmerged paths:
  (use "git reset HEAD <file>..." to unstage)
  (use "git add <file>..." to mark resolution)

    both modified:   two

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    four

In this case, files three and four are unrelated to the stash pop and have work-in-progress. If I have a lot of files in progress, it's difficult to go through and try to figure out what was or was not affected by the stash, and individually reset files or resolve conflicts.

I've searched all over SO but I cannot find a good way to just remove the effects of the stash pop. I can't just do git reset HEAD . to unstage the files. I've tried to create a patch from the stash and reverse apply it but it doesn't work because file two looks like this:

<<<<<<< Updated upstream
2.2
=======
2.1
>>>>>>> Stashed changes

With this file there should be a way to just keep the upstream changes and remove the stashed changes?

Do I have to suck it up and resolve the merge conflicts or is there a way to separate what was in my working directory before the stash pop?

SQB
  • 3,926
  • 2
  • 28
  • 49
Adam B
  • 554
  • 6
  • 18
  • Not to rub salt in it, but if you had committed before popping you could simply reset to the commit. I think you do have to resolve the conflict to salvage your work. – isherwood Mar 13 '15 at 20:15
  • For sure! I'm not currently dealing with this situation luckily but it's come up in my team before and I'm hoping there's a good way to sort it out. I actually think I may have found a way by adding all the files to the index and doing this to undo the stash merge: git merge-recursive stash@{0}: -- $(git write-tree) stash@{0}^1 (from here: http://stackoverflow.com/questions/8515729/aborting-a-stash-pop-in-git) - but i'm hoping someone can weigh in authoritatively because i'm unsure about this method! – Adam B Mar 13 '15 at 21:52

0 Answers0