如何让 git stash 包含尚未暂存的新文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37956397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make git stash include new files that have not been staged?
提问by Simon Tewsi
I'm no great expert at git but I've been using it for a couple of years. Lately I've noticed some strange behaviour relating to stashing. It seems to be only partially working for me.
我不是 git 的大专家,但我已经使用它几年了。最近我注意到一些与藏匿有关的奇怪行为。它似乎只对我有用。
For example today I tried to stash 4 uncommitted changes. 1 file was added to the stash, the remaining 3 stayed as uncommitted changes. Tried it a couple of times and after the first attempt I was just getting "No local changes to save", yet the status still showed the 3 uncommitted changes.
例如,今天我试图隐藏 4 个未提交的更改。1 个文件已添加到存储中,其余 3 个文件作为未提交的更改保留。尝试了几次,在第一次尝试后,我只是得到“没有要保存的本地更改”,但状态仍然显示 3 个未提交的更改。
However, by coincidence I found that when I first stage the previously unstashable changes, they will be stashed normally. I've played around and this is repeatable: If all changes are uncommitted, only the one change is stashed. If the "problem" changes are staged then all changes are stashed (doesn't matter whether the "good" change is staged or not, it will always stash).
然而,巧合的是,当我第一次暂存之前不可存储的更改时,它们会被正常存储。我已经玩过了,这是可重复的:如果所有更改都未提交,则只有一个更改被隐藏。如果“问题”更改已上演,则所有更改都将被隐藏(无论“好”更改是否已上演,它始终会被隐藏)。
Is this a bug or am I doing something wrong?
这是一个错误还是我做错了什么?
I'm using Git for Windows 2.8.2 and Git Extensions 2.48.05.
我使用 Git for Windows 2.8.2 和 Git Extensions 2.48.05。
It doesn't matter whether I try to stash the changes via the Git Extensions GUI or via the console.
我是否尝试通过 Git 扩展 GUI 或通过控制台隐藏更改都没有关系。
EDIT: If I stage all 4 changes before stashing, when I do a stash pop the 3 problem changes are staged, as before, but the good change, which always stashes, is uncommitted. So the stash pop does not round trip the status to the way it was before the stash. This is repeatable as well.
编辑:如果我在 stash 之前暂存所有 4 个更改,那么当我执行 stash pop 时,3 个问题更改会像以前一样暂存,但是总是隐藏的好的更改是未提交的。因此,stash pop 不会将状态返回到 stash 之前的状态。这也是可重复的。
回答by Jonathan.Brink
The problem seems to be that by default the stash
command will not include untracked files.
问题似乎是默认情况下该stash
命令不会包含未跟踪的文件。
To include untracked files, use the -u
(--include-untracked
) flag:
要包含未跟踪的文件,请使用-u
( --include-untracked
) 标志:
git stash -u
If the --include-untrackedoption is used, all untracked files are also stashed and then cleaned up with git clean, leaving the working directory in a very clean state.
如果使用--include-untracked选项,所有未跟踪的文件也会被隐藏起来,然后用 git clean 清理,使工作目录处于非常干净的状态。