git update-index --assume-unchanged returns error

空扰寡人 提交于 2019-12-05 10:27:36

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8598937/git-update-index-assume-unchanged-returns-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!