652

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?

double-beep
  • 5,031
  • 17
  • 33
  • 41
adardesign
  • 33,973
  • 15
  • 62
  • 84
  • 8
    Just a note to say that it appears that skip-worktree is in all likelihood what you would be better to be using than assume-unchanged, unless performance of git is your problem. http://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree – GreenAsJade Nov 29 '14 at 02:28

11 Answers11

841

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'
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
adardesign
  • 33,973
  • 15
  • 62
  • 84
  • 7
    Minor improvement to your grep statement, it could use '^[a-z]' to catch all ignored files, since the first letter tag could be letters other than 'H'/'h'. From http://git-scm.com/docs/git-ls-files: This option identifies the file status with the following tags (followed by a space) at the start of each line: H:: cached S:: skip-worktree M:: unmerged R:: removed/deleted C:: modified/changed K:: to be killed ?:: other – Bdoserror Feb 08 '14 at 23:59
  • 9
    Another useful trick is `git ls-files -v|grep '^h'|cut -c3-`, which will give you just the filenames, without the "h " prefix. – Retsam Oct 27 '14 at 16:59
  • 14
    If you don't know the files anymore that you `assume-unchanged`, just use `git update-index --really-refresh`. With that command, you don't need to look for the files with `git ls-files` first. – theDmi Sep 08 '15 at 07:41
  • 4
    It's worth mentioning that if you used `--skip-worktree`, the process to undo/revert it is very similar: list files with `git ls-files -v|grep '^S'` and revert with `git update-index --no-skip-worktree `. – geekley Sep 15 '21 at 01:09
  • Do not forget to stash your changes first. – Gerson Diniz Apr 17 '23 at 21:51
145

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-
SovietFrontier
  • 2,047
  • 1
  • 15
  • 33
adswebwork
  • 5,245
  • 3
  • 19
  • 9
59

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-
Will
  • 6,601
  • 3
  • 31
  • 42
  • 1
    For `git hidden`, you can achieve the same effect without shell aliases or scripts, using `!` like this: `hidden = ! git ls-files -v | grep '^h' | cut -c3-` – seanf Mar 01 '19 at 04:35
  • 1
    `--really-refresh` does not (or no longer does, perhaps it once did) clear the assume-unchanged flags on index files. – torek Aug 29 '19 at 06:24
  • 1
    Thank you, @torek! I confirmed the behavior you described, and I updated the answer with a different solution to the "reset all" case. – Will Aug 30 '19 at 13:24
46

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>
Ankit Vishwakarma
  • 1,573
  • 16
  • 13
  • git update-index --really-refresh , undo all assume-unchanged that I have made, thanks for the tip – Sérgio Oct 23 '14 at 23:24
  • `git update-index --no-assume-unchanged ` saved my life.. ok, I could just sync the folder again, but I did want a "real" solution for this problem. – Cagatay Ulubay Jan 22 '17 at 13:50
43

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.

hobbs
  • 223,387
  • 19
  • 210
  • 288
23

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
  1. git ls-files -v will print all files with their status
  2. grep '^[a-z]' will filter files and select only assume unchanged
  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-assume-unchanged will pass all paths separated by zero character to git update-index --no-assume-unchanged to undo
dmitry1100
  • 1,199
  • 12
  • 26
12

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.

sagunms
  • 8,030
  • 5
  • 41
  • 43
5

If you are using Git Extensions, then follow below steps:

  1. Go to commit window.
  2. Click on the dropdown named Working directory changes.
  3. Select Show assummed-unchanged files option.
  4. Right click on the file you want to unassumme.
  5. Select Do no assumme unchanged.

You are done.

Shivang Gupta
  • 3,139
  • 1
  • 25
  • 24
0

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.

Tyagi Akhilesh
  • 744
  • 6
  • 15
  • I think you would benefit from using `.gitignore` to ignore your build artifacts. – Nick Jun 12 '19 at 14:30
  • 1
    I have `.gitignore` but that is at times, in my experience is not sufficient. But I understand the context in which you are saying this. – Tyagi Akhilesh Jun 13 '19 at 05:50
0

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

  1. Open Git Bash and change to the relevant top level directory.
  2. git ls-files -v | grep '^^H' to list all the uncached files
  3. git 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
  4. 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
  5. 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 anything
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
-3

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.

Image shows the way to do it

flaxel
  • 4,173
  • 4
  • 17
  • 30