想象一下这个场景:
# edit two files
git add -p // add hunks from one file
现在当你跑步时git stash -p
,它会再次询问您是否要隐藏您刚刚通过选择的帅哥git add -p
。有没有办法配置 git 默认忽略这些已经添加的块?大多数时候,我不想隐藏我已经添加的东西。
联机帮助页中有一个类似的示例:
人 git 藏匿:
"Testing partial commits
You can use git stash save --keep-index when you want
to make two or more commits out of the changes in the
work tree, and you want to test each change before
committing:
# ... hack hack hack ...
$ git add --patch foo # add just first part to the index
$ git stash save --keep-index # save all other changes to the stash"*
我可以确认:
如果你使用git stash -p
(这意味着--keep-index
),您仍然会被问到是否应该隐藏索引中已有的更改(如您所描述的)。
因此,手册页似乎很混乱,这在其他地方也提到过:https://github.com/progit/progit2/issues/822 https://github.com/progit/progit2/issues/822
把它们加起来:
--keep-index
(or -p
这意味着--keep-index
)只是保持索引完好无损。已经上演的更改仍然会插入到存储中。而且据我所知,没有办法做到你所描述的。
或者,更准确地说(再次来自手册页):
With --patch, you can interactively select hunks from
the diff between HEAD and the working tree to be stashed.
The stash entry is constructed such that its index state
is the same as the index state of your repository, and its
worktree contains only the changes you selected interactively.
备择方案:
至少有 3 种方法可以实现你想要的(或多或少):
- 不要使用
-p
与 git stash 一起。隐藏所有东西(与--keep-index
并且可能--all
,以确保您已安全存放所有物品)。
- 在隐藏之前提交分阶段的更改。这样,对于您想要从存储中省略的这些更改,HEAD 和工作树之间就不会存在差异。但是,如果您还不确定是否要这样做怎么办?您可以随时进行更改并使用
--amend
更改现有提交。
- 取消暂存您的更改(从索引中删除),然后隐藏。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)