首页 文章

适用于git stash pop和git stash的区别

提问于
浏览
666

我已经使用 git stash pop 很长一段时间了 . 我最近发现了 git stash apply 命令 . 当我尝试它时,它似乎与 git stash pop 一样 .

git stash popgit stash apply 之间有什么区别?

4 回答

  • 23

    git stash pop throws away (最上面,默认情况下)应用后存储,而 git stash apply leaves it in the stash list 可能以后重用(或者你可以 git stash drop 它) .

    除非在 git stash pop 之后发生冲突,否则会发生这种情况,在这种情况下,它不会删除存储,其行为与 git stash apply 完全相同 .

    另一种看待它的方法: git stash popgit stash apply && git stash drop .

  • 1049

    得到了这个有用的链接,说明了差异,正如John Zwinck所说,以及Git stash pop的缺点 .

    例如,假设您的隐藏更改与您自首次创建存储后所做的其他更改发生冲突 . pop和apply都有助于触发合并冲突解决模式,让你很好地解决这些冲突......并且也不会摆脱存储,即使你可能期望流行 . 由于很多人都认为藏匿只是一个简单的堆栈,这通常会导致他们在以后意外地弹出相同的藏匿处,因为他们认为它已经消失了 .

    链接http://codingkilledthecat.wordpress.com/2012/04/27/git-stash-pop-considered-harmful/

  • 41

    git stash pop 应用顶部存储元素并将其从堆栈中删除 . git stash apply 做同样的事情,但将其留在存储堆栈中 .

  • 66

    看到它在行动可能会帮助您更好地理解差异 .

    假设我们正在处理 master 分支并且有一个包含"Hello"字符串的文件 hello.txt .

    让's modify the file and add 620987 string to it. Now you want to move to a different branch to fix a minor bug you' ve刚刚找到,所以你需要 stash 你的更改:

    git stash
    

    你移动到另一个分支,修复了错误,现在你已经准备好继续处理你的 master 分支,所以你 pop 的变化:

    git stash pop
    

    现在,如果您尝试查看您将获得的藏匿内容:

    $ git stash show -p
    No stash found.
    

    但是,如果您使用 git stash apply ,那么'll get the stashed content but you'也会保留它:

    $ 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
    

    所以 pop 就像堆栈's pop - it actually removes the element once it'弹出一样,而 apply 更像是偷看 .

相关问题