203

A while ago I did this to ignore changes to a file tracked by 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?

sazzad
  • 5,740
  • 6
  • 25
  • 42
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305

8 Answers8

288

Aha! I simply want:

git update-index --no-skip-worktree <file>
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
41

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!

Community
  • 1
  • 1
Stefan Anca
  • 1,386
  • 14
  • 23
  • 9
    Neat. I can use `git ls-files -v | grep '^S'` to list just files that I've "hidden" with skip-worktree. Hoped to make an alias "hidden" for that command, but putting a pipe redirection in the alias did not seem to work. – amacleod Feb 05 '14 at 19:36
  • 5
    @amacleod use a `!`. Like this `[alias] ignored = !git ls-files -v | grep "^S"` Tested, works. – Steven Lu Nov 19 '14 at 22:45
  • @amacleod Don't suppose you'd be able to suggest an alternative command for Windows? – Steve Chambers Sep 16 '15 at 10:05
  • 2
    @SteveChambers, Short of installing `grep`, I don't know. Depends on your shell, I guess. Git Bash does come with `grep`, I think. – amacleod Sep 16 '15 at 13:46
  • 1
    Brilliant, thanks @amacleod - just wasn't in my path. The only thing I needed to change for this to work on Windows was the quote style - `'` didn't work but `"` did, i.e. `git ls-files -v | grep "^S"` – Steve Chambers Sep 16 '15 at 13:55
32

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
dmitry1100
  • 1,199
  • 12
  • 26
13

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'
yossico
  • 3,421
  • 5
  • 41
  • 76
9

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)
eXavier
  • 4,821
  • 4
  • 35
  • 57
6

For those using 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
user276648
  • 6,018
  • 6
  • 60
  • 86
0

This answer is aimed at less technical people using Windows.

If you don't remember/know which files you clicked "skip-worktree" on then use:

git ls-files -v             //This will list all files, you are looking for the ones with an S at the beginning of the line. 

git ls-files -v | grep "S " //Use this to show only the lines of interest. Those are the files that have "skip-worktree".

To fix your problem:

You can go to the files -> right click -> restore to a previous version -> click the "git" tab on top -> uncheck the "skip-worktree" checkbox -> click "Apply" at the bottom.

If the files are too many to fix by hand then you'll need to refer to the other answers.

Bojidar Stanchev
  • 468
  • 5
  • 20
0

If you're a PowerShell user, here's some functions (aliases) inspired by @yossico's bash aliases

<#
Command: gitskipped
Description: List skipped files in git
Usage: gitskipped
#>
function gitskipped {
  (git ls-files -v $args) -split "\r\n" | Select-String -Pattern '^S ' | ForEach-Object {
    Write-Output $_.Line.Substring(2)
  }
}


<#
Command: gitskip
Description: Mark file(s) as "skip-worktree" in git
Usage: gitskip .env
#>
function gitskip {
  git update-index --skip-worktree $args
}


<#
Command: gitunskip
Description: Unmark file(s) as "skip-worktree" in git
Usage: gitunskip .env
#>
function gitunskip {
  git update-index --no-skip-worktree $args
}


<#
Command: gitunskipall
Description: Unmark all skipped files in git
Usage: gitunskipall
#>
function gitunskipall {
  $files = @((git ls-files -v $args) -split "\r\n" | Select-String -Pattern '^S ' | ForEach-Object { $_.Line.Substring(2) })
  git update-index --no-skip-worktree $files
}
simshaun
  • 21,263
  • 1
  • 57
  • 73