I've been using git stash pop
for quite some time. I recently found out about the git stash apply
command. When I tried it out, it seemed to work the same as git stash pop
.
What is the difference between git stash pop
and git stash apply
?
I've been using git stash pop
for quite some time. I recently found out about the git stash apply
command. When I tried it out, it seemed to work the same as git stash pop
.
What is the difference between git stash pop
and git stash apply
?
git stash pop
throws away the (topmost, by default) stash after applying it, whereasgit stash apply
leaves it in the stash list for possible later reuse (or you can thengit stash drop
it).This happens unless there are conflicts after
git stash pop
, in this case, it will not remove the stash, behaving exactly likegit stash apply
.Another way to look at it:
git stash pop
isgit stash apply && git stash drop
.Seeing it in action might help you better understanding the difference.
Assuming we're working on
master
branch and have a filehello.txt
that contains "Hello" string.Let's modify the file and add " world" string to it. Now you want to move to a different branch to fix a minor bug you've just found, so you need to
stash
your changes:You moved to the other branch, fixed the bug and now you're ready to continue working on your
master
branch, so youpop
the changes:Now if you try to review the stash content you'll get:
However, if you use
git stash apply
instead, you'll get the stashed content but you'll also keep it:So
pop
is just like stack's pop - it actually removes the element once it's popped, whileapply
is more like peek.Got this helpful link that states the difference, as John Zwinck has stated and a drawback of Git stash pop.
Link http://codingkilledthecat.wordpress.com/2012/04/27/git-stash-pop-considered-harmful/
git stash pop
applies the top stashed element and removes it from the stack.git stash apply
does the same, but leaves it in the stash stack.