Difference between git stash pop and git stash apply
我已经使用
除非在
另一种看待它的方法:
得到了这个有用的链接,说明了差异,正如John Zwinck所述,以及Git stash pop的缺点。
For instance, say your stashed changes conflict with other changes that you’ve made since you first created the stash. Both pop and apply will helpfully trigger merge conflict resolution mode, allowing you to nicely resolve such conflicts… and neither will get rid of the stash, even though perhaps you’re expecting pop to. Since a lot of people expect stashes to just be a simple stack, this often leads to them popping the same stash accidentally later because they thought it was gone.
链接http://codingkilledthecat.wordpress.com/2012/04/27/git-stash-pop-considered-harmful/
看到它在行动可能会帮助您更好地理解差异。
假设我们正在处理
让我们修改文件并为其添加"world"字符串。现在您想要移动到另一个分支来修复您刚刚找到的小错误,因此您需要
1 | git stash |
您移动到另一个分支,修复了错误,现在您已准备好继续处理
1 | git stash pop |
现在,如果您尝试查看您将获得的藏匿内容:
1 2 | $ git stash show -p No stash found. |
但是,如果您使用
1 2 3 4 5 6 7 8 | $ git stash show -p diff --git a/hello.txt b/hello.txt index e965047..802992c 100644 --- a/hello.txt +++ b/hello.txt @@ -1 +1 @@ -Hello +Hello world |
所以
Git Stash
如果您想将最高级别的更改应用于当前的非暂存更改并删除该存储,那么您应该转到
1 2 | # apply the top stashed changes and delete it from git stash area. git stash pop |
但是如果你想在不删除它的情况下将你的顶级存储更改应用到当前的非分段更改,那么你应该去
Note : You can relate this case with
Stack classpop() andpeek() methods, where pop change the top by decrements (top = top-1) butpeek() only able to get the top element.
在
当您想要从
1 2 3 | git stash apply //apply the changes without removing stored files from stash area. git stash pop // apply the changes as well as remove stored files from stash area. |
Note :-
git apply only apply the changes from stash area whilegit pop apply as well as remove change fromstash area.