撤消 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:59:22  来源:igfitidea点击:

Undo git update-index --skip-worktree

gitundo

提问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
  1. git ls-files -vwill print all files with their status
  2. grep -i ^Swill filter files and select only skip worktree (S) or skip worktree and assume unchanged (s), -i means ignore case sensitive
  3. cut -c 3-will remove status and leave only paths, cutting from the 3-rd character to the end
  4. tr '\012' '\000'will replace end of line character (\012) to zero character (\000)
  5. xargs -0 git update-index --no-skip-worktreewill pass all paths separated by zero character to git update-index --no-skip-worktreeto undo
  1. git ls-files -v将打印所有文件及其状态
  2. grep -i ^S将过滤文件并仅选择跳过工作树(S)或跳过工作树并假设未更改(s),-i 表示忽略大小写敏感
  3. cut -c 3-将删除状态并只留下路径,从第 3 个字符到结尾
  4. tr '\012' '\000'将行尾字符 (\012) 替换为零字符 (\000)
  5. 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 的人:

  1. Right click on the folder or on the specific file, then choose TortoiseGit > Check for modifications
  2. 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)
  3. Right click on the file and choose Unflag as skip-worktree and assume-unchanged
  1. 右键单击文件夹或特定文件,然后选择 TortoiseGit > Check for modifications
  2. 只检查Show ignore local changes flagged files。您应该看到您忽略的文件(或您忽略的所有文件,如果您右键单击了文件夹)
  3. 右键单击文件并选择 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)

##代码##