Reputation: 35781
I have run the following command to ignore watching/tracking a particular directory/file:
git update-index --assume-unchanged <file>
How can I undo this, so that <file>
is watched/tracked again?
Upvotes: 705
Views: 272588
Reputation: 8525
Adding to @adardesign
's answer, if you want to reset all files that have been added to assume-unchanged
list to no-assume-unchanged
in one go, you can do the following:
git ls-files -v | grep '^h' | sed 's/^..//' | sed 's/\ /\\ /g' | xargs -I FILE git update-index --no-assume-unchanged FILE || true
This will just strip out the two characters output from grep i.e. "h "
, then escape any spaces that may be present in file names, and finally || true
will prevent the command to terminate prematurely in case some files in the loop has errors.
Upvotes: 15
Reputation: 1329
If you want to undo all files that was applied assume unchanged with any status, not only cached (git marks them by character in lower case), you can use the following command:
git ls-files -v | grep '^[a-z]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchanged
git ls-files -v
will print all files with their statusgrep '^[a-z]'
will filter files and select only assume unchangedcut -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-assume-unchanged
will pass all paths separated by zero character to git update-index --no-assume-unchanged
to undoUpvotes: 24
Reputation: 7057
To synthesize the excellent original answers from @adardesign, @adswebwork and @AnkitVishwakarma, and comments from @Bdoserror, @Retsam, @seanf, and @torek, with additional documentation links and concise aliases...
Basic Commands
To reset a file that is assume-unchanged back to normal:
git update-index --no-assume-unchanged <file>
To list all files that are assume-unchanged:
git ls-files -v | grep '^[a-z]' | cut -c3-
To reset all assume-unchanged files back to normal:
git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git update-index --no-assume-unchanged --
Note: This command which has been listed elsewhere does not appear to reset all assume-unchanged files any longer (I believe it used to and previously listed it as a solution):
git update-index --really-refresh
Shortcuts
To make these common tasks easy to execute in git, add/update the following alias section to .gitconfig
for your user (e.g. ~/.gitconfig
on a *nix or macOS system):
[alias]
hide = update-index --assume-unchanged
unhide = update-index --no-assume-unchanged
unhide-all = ! git ls-files -v | grep '^[a-z]' | cut -c3- | xargs git unhide --
hidden = ! git ls-files -v | grep '^[a-z]' | cut -c3-
Upvotes: 68
Reputation: 5505
If this is a command that you use often - you may want to consider having an alias for it as well. Add to your global .gitconfig
:
[alias]
hide = update-index --assume-unchanged
unhide = update-index --no-assume-unchanged
How to set an alias (if you don't know already):
git config --configLocation alias.aliasName 'command --options'
Example:
git config --global alias.hide 'update-index --assume-unchanged'
git config... etc
After saving this to your .gitconfig
, you can run a cleaner command.
git hide myfile.ext
or
git unhide myfile.ext
This git documentation was very helpful.
As per the comments, this is also a helpful alias to find out what files are currently being hidden:
[alias]
hidden = ! git ls-files -v | grep '^h' | cut -c3-
Upvotes: 163
Reputation: 35781
To get undo/show dir's/files that are set to assume-unchanged run this:
git update-index --no-assume-unchanged <file>
To get a list of dir's/files that are assume-unchanged
run this in a unix shell:
git ls-files -v | grep '^h'
or in a PowerShell:
git ls-files -v | Select-String -CaseSensitive '^h'
Upvotes: 896
Reputation: 21
So this happened! I accidently clicked on "assume unchanged"! I tried searching on Internet, but could not find any working solution! So, I tried few things here and there and finally I found the solution (easiest one) for this which will undo the assume unchanged!
Right click on "Your Project" then Team > Advanced > No assume Unchanged
.
Upvotes: -1
Reputation: 39464
None of the solutions worked for me in Windows - it seems to use capital H
rather than h
for the file status and the grep command requires an extra caret as ^
also represents the start of line as well as negating the next character.
Windows solution
git ls-files -v | grep '^^H'
to list all the uncached filesgit ls-files -v | grep '^^H' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-skip-worktree
to undo the files skipping of all files that was done via update-index --skip-worktree
git ls-files -v | grep '^^H]' | cut -c 3- | tr '\012' '\000' | xargs -0 git update-index --no-assume-unchanged
to undo the files skipping of all files that was done via update-index --assume-unchanged
git ls-files -v | grep '^^H'
to again list all the uncached files and check whether the above commands have worked - this should now not return anythingUpvotes: 0
Reputation: 860
Nothing here that is not covered. But would like to add my 2 cents. At times, I run a build and it changes lot of files and then I want to work on something, so this command really helps me a lot.
git update-index --assume-unchanged `git status | grep modified | sed 's|modified:||g'| xargs`
Hope someone else find it useful as well.
Upvotes: 1
Reputation: 3339
If you are using Git Extensions, then follow below steps:
You are done.
Upvotes: 8
Reputation: 1691
git update-index function has several option you can find typing as below:
git update-index --help
Here you will find various option - how to handle with the function update-index.
[if you don't know the file name]
git update-index --really-refresh
[if you know the file name ]
git update-index --no-assume-unchanged <file>
will revert all the files those have been added in ignore list through.
git update-index --assume-unchanged <file>
Upvotes: 49
Reputation: 240759
I assume (heh) you meant --assume-unchanged
, since I don't see any --assume-changed
option. The inverse of --assume-unchanged
is --no-assume-unchanged
.
Upvotes: 46