Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo git update-index --skip-worktree

Tags:

git

undo

People also ask

What is Skip Worktree?

--skip-worktree explained: This allows you to make changes to a file that you don't want to be pushed to upstream. Use this option as already shown above.

How to assume unchanged git?

In order to set "assume unchanged" bit, use --assume-unchanged option. To unset, use --no-assume-unchanged . To see which files have the "assume unchanged" bit set, use git ls-files -v (see git-ls-files[1]). The command looks at core.

What does git update index do?

Overview. We use git update-index when we want to manually operate on files in Git staging area. This command supports two options that are often misused: –assume-unchanged and –skip-worktree. In this tutorial, we'll see how these two options differ and provide a use case for each.


Aha! I simply want:

git update-index --no-skip-worktree <file>

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!


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

For all of you that love Bash aliases, here is my set to rule them all(based on C0DEF52)

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'

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)