git update-index --assume-unchanged 返回错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8598937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:16:53  来源:igfitidea点击:

git update-index --assume-unchanged returns error

gitignore

提问by Sreeram Ravinoothala

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

git update-index --assume-unchanged <filename>返回fatal: Unable to mark file <filename>

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

我需要做什么来解决这个问题?它在抱怨什么?为什么?

采纳答案by Pedro Nascimento

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

它是否已添加到存储库,而不是 in.git/info/exclude和 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 -oand see if the file is there. It should not be.

试试看git ls-files -o文件是否在那里。不应该。

回答by funroll

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

您正在运行git update-index --assume-unchanged是因为您有文件已签入存储库,但您想忽略本地编辑。

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 -owhich means it's untracked.)

正如 Pedro 指出的那样,给您错误的文件没有被检入存储库。(它出现在git ls-files -o这意味着它没有被跟踪。)

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 certainthat 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-unchangedcan be a pain.

但要小心。请注意,弄乱--assume-unchanged可能会很痛苦。

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

考虑重新工作,以便这些文件根本不需要在 repo 中。然后,您可以将它们添加到您.gitignore的存储库中并使用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.

如果您可以将文件保留在 repo 和用户工作目录之外,那可能是理想的。例如,如果文件是作为构建的一部分创建的,您可以创建一个静态库,而不是让每个开发人员在本地运行构建过程。