git update-index --assume-unchanged
returns fatal: Unable to mark file
.
What do I need to do to fix this? Wha
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.
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.
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.