19

git update-index --assume-unchanged <filename> returns fatal: Unable to mark file <filename>.

What do I need to do to fix this? What is it complaining about and why?

Austin Moore
  • 1,414
  • 6
  • 20
  • 43

4 Answers4

16

Is it added to the repository, not in .git/info/exclude and not on .gitignore?

If the answer is yes to either of those, then the file is not in the repository and this is the reason for the error.

Try git ls-files -o and see if the file is there. It should not be.

Austin Moore
  • 1,414
  • 6
  • 20
  • 43
Pedro Nascimento
  • 13,136
  • 4
  • 36
  • 64
  • You'll still get this same error if your files are staged, so you may need to do a `git reset HEAD ` first. – DavidJ Aug 08 '13 at 17:29
  • I had to update `.git/info/exclude` file to ignore the file. don't know why it's not with `update-index`. it used to work just fine before. – Mejan Apr 28 '22 at 05:49
6

You are running git update-index --assume-unchanged because you have files that are checked into the repository but you want to ignore local edits.

As Pedro points out, the file that's giving you the error is not checked into the repository. (It shows up in git ls-files -o which means it's untracked.)

This may come about because you're trying to ignore an entire directory recursively like so:

find ./folder/ -type f | xargs git update-index --assume-unchanged

But not only are files in that folder modified, new files have been created. (e.g. by a build script.)

If you are certain that you want to ignore all modified files, you can do so with this command:

git ls-files -m | xargs git update-index --assume-unchanged

But watch out. Be aware that messing with --assume-unchanged can be a pain.

Consider re-working things so those files don't need to be in the repo at all. Then you can add them to your .gitignore and delete them from the repository with git rm --cached.

If you can keep the files out of both the repo and the users working directories, that may be ideal. For example, if the files are created as part of building, you could create a static library instead of having each developer run the build process locally.

funroll
  • 35,925
  • 7
  • 54
  • 59
1

For those wo have this issue trying to exlude a whole directory:

I just had this issue and got quite confused. I had the directory added in .gitignore and one of the files showed up in git ls-files -o. Other files of this directory showed up in git status.

I finally figured out that I had to treat the files in the directory differently, because some of them were already tracked and some were not. So I just used git update-index --skip-worktree <file> (the in my case better version of git update-index --assume-unchanged <filename>, see here) on the files that were already tracked (the ones showing up in git status as being modified). In comparison to calling this command on the whole directory, this worked because I didn't try to exclude files that were not tracked yet and already excluded by .gitignore. The other files in this directory I didn't have to exclude with this command because they were already excluded by .gitignore.

Kaldena
  • 36
  • 1
  • 1
0

First, stage your file. Then, only after that, run --assume-unchanged. Finally, unstage the file.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Andrii Viazovskyi
  • 777
  • 2
  • 9
  • 15