Git stash应用和丢弃

56

有没有一个 git 命令既应用存储(stash)又将其删除?

将其合并成一个命令:

git stash apply
git stash drop
2个回答

86
你想要使用 git stash pop
pop [--index] [-q|--quiet] [<stash>]
       Remove a single stashed state from the stash list and apply it on
       top of the current working tree state, i.e., do the inverse
       operation of git stash save. The working directory must match the
       index.

15
请注意,如果由于“git stash pop”而导致冲突,则储藏不会被删除。解决冲突后(最好进行提交),您需要自己丢弃储藏。 - Johan Fredrik Varen
@Adam 但是如果我想要像 stash@{1} 这样特定的存储,而且仍然不想为此执行两个命令 applydrop,该怎么办呢? - Vicky Dev
@Adam 但是如果我想要像 stash@{1} 这样 git stash pop 特定的储藏,并且仍然不想要执行两个命令 applydrop,该怎么办呢? - undefined

23

git stash pop会取出你列表中的第一个储藏(或你指定的),将其应用到你的HEAD上,并将其从储藏列表中删除。


但是如果我想要像stash@{1}这样特定的存储,而且仍然不想为此执行2个命令applydrop,该怎么办? - Vicky Dev
@VickyDev,re,实际上,回答已经解决了这个问题:你可以使用git stash pop 1来恢复首选的stash。 - LSpice

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接