git 如何隐藏当前文件夹中的更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16434267/
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 stash changes in current folder?
提问by stdcall
I would like to stash the changes only the changes in the current folder and it's subfolders.
我想只存储当前文件夹及其子文件夹中的更改。
How can I achieve that?
我怎样才能做到这一点?
I tried the obvious approach - git stash .
but it doesn't seems to work.
我尝试了显而易见的方法 -git stash .
但它似乎不起作用。
I know I can create temporary commits and delete them afterward, but I want to know if git stash
supports stashing specific folders.
我知道我可以创建临时提交并在之后删除它们,但我想知道是否git stash
支持隐藏特定文件夹。
回答by gorpacrate
git stash push -- path/to/folder
Does the trick for me.
对我有用。
回答by Marco Leogrande
git stash
will not let you save partial directories with a single command, but there are some alternatives.
git stash
不会让您使用单个命令保存部分目录,但有一些替代方法。
You can use git stash -p
to select only the diffs that you want to stash.
您可以使用git stash -p
仅选择要隐藏的差异。
If the output of git stash -p
is huge and/or you want a scriptable solution, and it is acceptable to create temporary commits, you can create a commit with all the changes but those in the subdirectory, then stash away the changes, and rewind the commit. In code:
如果 的输出git stash -p
很大和/或您想要一个可编写脚本的解决方案,并且创建临时提交是可以接受的,您可以创建一个包含除子目录中的所有更改之外的所有更改的提交,然后隐藏更改,并回滚提交。在代码中:
git add -u :/ # equivalent to (cd reporoot && git add -u) without changing $PWD
git reset HEAD .
git commit -m "tmp"
git stash # this will stash only the files in the current dir
git reset HEAD~
回答by mvp
This should work for you:
这应该适合你:
cd <repo_root>
git add . # add all changed files to index
cd my_folder
git reset . # except for ones you want to stash
git stash -k # stash only files not in index
git reset # remove all changed files from index
Basically, it adds all changed files to index, except for folder (or files) you want to stash. Then you stash them using -k
(--keep-index
). And finally, you reset index back to where you started.
基本上,它会将所有更改的文件添加到索引中,除了要存储的文件夹(或文件)。然后你使用-k
( --keep-index
)隐藏它们。最后,您将索引重置回您开始的位置。
回答by Xylarax
You could checkout one of the GUI git interfaces like SourceTree or TortoiseGit, things like this are what I personally go to tortoise for as it just ends up being much faster than trying to do many commandline commands.
您可以查看其中一个 GUI git 界面,例如 SourceTree 或 TortoiseGit,像这样的事情是我个人使用 tortoise 的目的,因为它最终比尝试执行许多命令行命令要快得多。