Undo git update-index --skip-worktree

匿名 (未验证) 提交于 2019-12-03 01:54:01

问题:

A while ago I did this to ignore changes to a file tracked by git:

git update-index --skip-worktree 

Now I actually want to commit changes to that file to source. How do I undo the effects of skip-worktree?

Thanks, Kevin

回答1:

Aha! I simply want:

git update-index --no-skip-worktree 


回答2:

According to http://www.kernel.org/pub/software/scm/git/docs/git-update-index.html, use

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.

Edit: As @amacleod mentioned, 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!



回答3:

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 '\012' '\000' | xargs -0 git update-index --no-skip-worktree 
  1. git ls-files -v will print all files with their status
  2. grep -i ^S will 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-worktree will pass all paths separated by zero character to git update-index --no-skip-worktree to undo


回答4:

Based on @GuidC0DE answer, here's a version for Powershell (I use posh-git)

git update-index --no-skip-worktree $(git ls-files -v | sls -pattern "^S"| %{$_.Line.Substring(2)}) 

And for reference also the opposite command to hide the files:

git update-index --skip-worktree $(git ls-files --modified) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!