我想隐藏更改当前文件夹及其子文件夹中的更改.
我怎样才能做到这一点?
我尝试了一种显而易见的方法 - git stash .
但似乎没有用.
我知道我可以创建临时提交并在之后删除它们,但我想知道是否git stash
支持存储特定文件夹.
gor*_*ate 60
git stash push -- path/to/folder
Run Code Online (Sandbox Code Playgroud)
对我来说是诀窍.
Mar*_*nde 12
git stash
不会让你用一个命令保存部分目录,但有一些替代方案.
您可以使用git stash -p
仅选择要隐藏的差异.
如果输出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~
Run Code Online (Sandbox Code Playgroud)
这应该适合你:
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
Run Code Online (Sandbox Code Playgroud)
基本上,它将所有已更改的文件添加到索引,但要隐藏的文件夹(或文件)除外.然后用-k
(--keep-index
)隐藏它们.最后,将索引重置回您开始的位置.