在我的当前分支上,我有几个存储:
stash@{0}
stash@{1}
stash@{2}
如果我应用stash@{0}
:
$ git stash apply stash{0}
修改这个stash
我想保存更改到当前stash stash@{0}
我不想创建第四个stash,我只想更新第一个stash。
有人可以告诉我如何做吗?我在看man页面...也许我忽略了什么。
您可以储存您的工作区,然后删除您不需要的旧工作区。
git stash apply
# Make changes
git stash
git stash drop stash@{1}
或者,您可以使用pop而不是apply,这将同时删除stash:
git stash pop
# make changes
git stash
如果你在意识到要将修改内容合并到储藏栈顶部之前已经进行了需要做的更改,那么另一个选择是:
# make changes
git add <all files>
git stash pop # or apply
git rm --cached <files that you want to merge>
git stash --keep-index
我也需要做这件事。
我主要使用 git stash 的方式
我保留了一组我经常想要应用(而不是弹出)的存储。例如,我有一个存储,应用它会应用与存储库中所检入的不同的某种配置。在获取最新版本后,我只需在检查存储列表后运行类似于 git stash apply 0
的命令。
我刚遇到的问题
应用存储时,您可能会遇到合并冲突。当出现这种情况时,您被迫解决合并冲突。这显然不是每次应用存储时都想要做的事情。
解决方案
除非您要应用的项位于堆栈顶部,否则这显然不会使索引保持不变,但对我来说可以。我只关心我在存储中是否有该项,而不关心它相对于其他存储项的位置。
# Find the item in the stash I'm trying to apply, based on the description.
git stash list
# Apply the stashed item, based on its index.
git stash apply 0
# Merge conflicts found... correct them.
git mergetool
# Drop the stash by whatever index was found.
# This is necessary since doing a git stash pop doesn't remove a stash that has merge-conflicts.
# In that scenario, it says "The stash entry is kept in case you need it again."
git stash drop 0
# Resave the stash with the merge-conflicts taken care of.
git stash save "Some message for identifying the stash in the list"
最顶端的stash
,还是需要修改特定索引处的stash并保存回该索引?后者将会非常有趣。 - Ashish Gaurstash^
是创建存储时的HEAD
提交,stash^2
是创建存储时的索引状态,而stash^3
(如果存在)则包含未跟踪/忽略的文件。stash
本身代表了工作树状态。 - torek