撤消 git update-index --skip-worktree
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11131197/
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
Undo git update-index --skip-worktree
提问by Kevin Burke
A while ago I did this to ignore changes to a file tracked by git:
不久前,我这样做是为了忽略对 git 跟踪的文件的更改:
git update-index --skip-worktree <file>
Now I actually want to commit changes to that file to source. How do I undo the effects of skip-worktree
?
现在我实际上想将该文件的更改提交到源。如何撤消 的影响skip-worktree
?
回答by Kevin Burke
Aha! I simply want:
啊哈!我只想:
git update-index --no-skip-worktree <file>
回答by Stefan Anca
According to http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html, use
根据http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html,使用
git ls-files -v
git ls-files -v
to see the "assume unchanged" and "skip-worktree" files marked with a special letter. The "skip-worktree" files are marked with S
.
查看标有特殊字母的“假设未更改”和“跳过工作树”文件。“skip-worktree”文件标有S
.
Edit: As @amacleodmentioned, making an alias to list all the hidden files is a nice trick to have so that you don't need to remember it. I use alias hidden="git ls-files -v | grep '^S'"
in my .bash_profile. It works great!
编辑:正如@amacleod 所提到的,创建一个别名来列出所有隐藏文件是一个很好的技巧,这样您就不需要记住它。我alias hidden="git ls-files -v | grep '^S'"
在我的 .bash_profile 中使用。它工作得很好!
回答by C0DEF52
If you want to undo all files that was applied skip worktree, you can use the following command:
如果要撤消已应用跳过工作树的所有文件,可以使用以下命令:
git ls-files -v | grep -i ^S | cut -c 3- | tr '2' 'git update-index --no-skip-worktree $(git ls-files -v | sls -pattern "^S"| %{$_.Line.Substring(2)})
0' | xargs -0 git update-index --no-skip-worktree
git ls-files -v
will print all files with their statusgrep -i ^S
will filter files and select only skip worktree (S) or skip worktree and assume unchanged (s), -i means ignore case sensitivecut -c 3-
will remove status and leave only paths, cutting from the 3-rd character to the endtr '\012' '\000'
will replace end of line character (\012) to zero character (\000)xargs -0 git update-index --no-skip-worktree
will pass all paths separated by zero character togit update-index --no-skip-worktree
to undo
git ls-files -v
将打印所有文件及其状态grep -i ^S
将过滤文件并仅选择跳过工作树(S)或跳过工作树并假设未更改(s),-i 表示忽略大小写敏感cut -c 3-
将删除状态并只留下路径,从第 3 个字符到结尾tr '\012' '\000'
将行尾字符 (\012) 替换为零字符 (\000)xargs -0 git update-index --no-skip-worktree
将通过零字符分隔的所有路径git update-index --no-skip-worktree
来撤消
回答by eXavier
Based on @GuidC0DE answer, here's a version for Powershell (I use posh-git)
基于@GuidC0DE 的回答,这里有一个 Powershell 版本(我使用posh-git)
git update-index --skip-worktree $(git ls-files --modified)
And for reference also the opposite command to hide the files:
并参考相反的命令来隐藏文件:
alias gitskip='git update-index --skip-worktree ' #path to file(s)
alias gitlistskiped='git ls-files -v | grep ^S'
alias gitunskip='git update-index --no-skip-worktree ' #path to file(s)
alias gitunskipall='git ls-files -v | grep -i ^S | cut -c 3- | tr ''\012'' ''\000'' | xargs -0 git update-index --no-skip-worktree'
回答by user276648
For those using Tortoise Git:
对于那些使用 Tortoise Git 的人:
- Right click on the folder or on the specific file, then choose
TortoiseGit > Check for modifications
- Only check
Show ignore local changes flagged files
. You should see the file that you ignored (or all the files you've ignored, if you've right clicked on the folder) - Right click on the file and choose
Unflag as skip-worktree and assume-unchanged
- 右键单击文件夹或特定文件,然后选择
TortoiseGit > Check for modifications
- 只检查
Show ignore local changes flagged files
。您应该看到您忽略的文件(或您忽略的所有文件,如果您右键单击了文件夹) - 右键单击文件并选择
Unflag as skip-worktree and assume-unchanged
回答by yossico
For all of you that love Bash aliases, here is my set to rule them all(based on C0DEF52)
对于所有喜欢 Bash 别名的人,这里是我的规则(基于 C0DEF52)
##代码##