hi i'm cameron mckenzie i'm the editor-in-chief over at the serverside.com you can follow me on
twitter at cameronmcnz and i want to talk to you about how to merge and resolve some
stash pop conflicts just in case you run into them now for this example i've initialized a
git repository i've put a file in here called stash pop conflict i've added it to the index
and then done a little commit just so that i can create a stash issue on my own and
the idea with working with the stash is that you're going to edit some files i'm going to
edit that stash pop conflict file right here by just typing hello world into there may as well
there we go that just edits the file now imagine
for some reason you needed to stash that file if you say git stash i think you did get stash
push if you really want you just have to say get stash it's the same thing as git stash push
and all of a sudden i've now stashed my file in that state now let's imagine that
i do a little bit more work and so maybe i change from hello world to goodbye world
then maybe do a little commit
and do a little get ref log just to show you everything that's in there probably do even
a little ls file and show you it's that stash pop conflict file that i'm working
on okay so i have now edit i've now done a commit i've edited the file and stashed it
i've then done another edit on the file committed it now if i go in and try and pop that stash
and overwrite the stash pop conflict file the tool is going to complain it's going to say look you're
going to overwrite something that's committed this is a a bad idea and you're going to have to deal
with it so let's do that git stash pop see what happens and there you go it says conflict content
merge conflict in stash pop conflict.html file and so what it's done to me right now is it's
i've actually a bunch of edits into this file you can see it here that's the
file on my local file system and it's kind of put all of my code together it said you know
the original stuff is this that was in the stash the stuff that's committed it's it's that how
do you want to resolve that well the way that we resolve it is we go in there and we actually just
edit the file and figure out how we want to merge it
and so that's what the file looks like right now i mean you can merge it any way that you want
click save that is now saved now i can come over here that file has been successfully merged
but it's not in the index so i've got to do a git add command and then a git commit command as well
and life is good now one thing to notice is that if you do a get list command
a git stash list it's actually still going to list that pop in the stash that stash that was popped
and the reason for that is when there's a conflict the stash isn't actually deleted
so normally a pop gets deleted after it overwrites your working files but if there's a conflict
that doesn't happen just so you have the ability to go back to it so just keep that in mind if you
do want to get rid of it it's just a matter of saying git stash drop and now if i do a git list
everything is there is gone kit stash list everything there is gone and i'm back to the
way i wanted it before or at least after i did the pop and there you go that's how you merge
and resolve conflicts with your git stash pop if you enjoyed the tutorial i want you to head over
to theserverside.com i'm the editor-in-chief over there we've got lots of great tutorials
on git github devops tools and cloud native development if you're interested in my personal
antics you can always follow me on twitter at cameronmcnz and hey subscribe on the youtube