我有一个肮脏的工作目录,用于git stash save -p选择性地存储一些更改。我的目的是将原来的一个大提交分成两个较小的提交。现在的问题是我不小心藏了错误的重击,所以我想再做一次。我尝试按照此问题git stash pop中的建议执行 a ,但这样做会出现此错误:
error: Your local changes to the following files would be overwritten by merge:
my_file.js
Please, commit your changes or stash them before you can merge.
Aborting
Run Code Online (Sandbox Code Playgroud)
对我来说,以下内容就足够了:
% git add myfile.js
% git stash pop
% git reset myfile.js
Run Code Online (Sandbox Code Playgroud)
或者,提交 myfile.js,然后弹出存储,解决任何冲突。为了摆脱虚拟提交,git reset --soft HEAD^. 就像是:
% git add myfile.js
% git commit
% git stash pop
# resolve conflicts if needed
% git reset --soft HEAD^
Run Code Online (Sandbox Code Playgroud)
--soft意味着不要触及工作树或索引;HEAD^表示最后一次提交之前的提交。
该手册实际上提到了这种行为,尽管我直到现在才注意到它:
Run Code Online (Sandbox Code Playgroud)pop [--index] [-q|--quiet] [<stash>]从存储列表中删除单个存储状态并将其应用到当前工作树状态之上,即执行 的逆操作
git stash save。工作目录必须与索引匹配。
(强调我的)当我们这样做时git add,我们会导致索引和工作目录匹配(它们都包含未隐藏的更改)。同样,当我们创建提交时,它们会匹配。(它们都没有变化)
| 归档时间: |
|
| 查看次数: |
938 次 |
| 最近记录: |