4

i am wondering how can i take the stashed version of the files.

say i have a file called foo.c with some uncommitted changes on master and i would like to update the current branch from remote. Remote has also modified foo.c

My current approach is to:

stash the current changes on master
git pull --rebase

this goes well.

but when i do a:

 git stash pop

there will be a merge conflict in foo.c

so is there a way to take stashed version of foo.c?

i.e similar to what can be done with pulling:

 git pull -s recursive -X theirs --rebase

so what i am looking for is:

 git stash pop "-X theirs"

that would replace the pulled version of foo.c with the stashed version

tnx for the help

SevenEleven
  • 2,326
  • 2
  • 32
  • 32
mher
  • 369
  • 3
  • 7
  • 2
    Have you tried resolving the merge conflicts? – pedrotorres Nov 30 '15 at 14:29
  • 1
    yes, but i don't like that solution. i would like to replace whatever has been pulled with the stashed version. looking at the help of git stash, the workflow i am looking for is not described :S – mher Nov 30 '15 at 14:34
  • 1
    Ah, yes, I see what you're looking for. Perhaps this can help you? [Link](http://stackoverflow.com/questions/16861982/how-to-cherry-pick-from-stash-in-git) – pedrotorres Nov 30 '15 at 14:41
  • another solution i thought of is to merge the WIP commit that 'git stash' creates. but i think that defeats the reason for using git stash in the first place. as i could just create a dummy branch, pull the remote changes and merge that dummy branch on top of master... – mher Nov 30 '15 at 14:42
  • hmm, @peacewalker that is a possibility, still not a one liner though :) – mher Nov 30 '15 at 14:45
  • 1
    What about `git stash branch ` and `git cherry-pick -X theirs`? – SevenEleven Nov 30 '15 at 14:56
  • if it is a one-off and you know where the conflict happens, just delete that file in the working dir before popping the stash. – mnagel Nov 30 '15 at 16:43
  • i actually use it quite often. so i guess i'll create a git alias for that using @SevenEleven's suggestion – mher Nov 30 '15 at 20:08

0 Answers0