git update-index --assume-unchanged 返回错误
git update-index --assume-unchanged
返回 fatal: 无法标记文件
。
我需要做什么来解决这个问题?它抱怨什么以及为什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它是否添加到存储库中,而不是在
.git/info/exclude
中,也不在.gitignore
中?如果其中任何一个的答案是肯定的,则该文件不在存储库中,这就是错误的原因。
尝试 git ls-files -o 并查看该文件是否存在。不应该的。
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.您正在运行 git update-index --assume-unchanged ,因为您有已签入存储库的文件,但您希望忽略本地编辑。
正如 Pedro 指出的那样,给您带来错误的文件未签入存储库。 (它显示在 git ls-files -o 中,这意味着它未被跟踪。)
这可能是因为您试图像这样递归地忽略整个目录:
但不仅是该文件夹中的文件修改后,新文件已创建。 (例如通过构建脚本。)
如果您确定想要忽略所有修改的文件,您可以使用以下命令来执行此操作:
但是要小心。 请注意,弄乱
--assume-unchanged
可能会很痛苦。考虑重新处理事情,以便这些文件根本不需要位于存储库中。然后,您可以将它们添加到
.gitignore
中,并使用git rm --cached
从存储库中删除它们。如果您可以将文件保留在存储库和用户工作目录之外,那可能是理想的选择。例如,如果文件是作为构建的一部分创建的,您可以创建一个静态库,而不是让每个开发人员在本地运行构建过程。
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:
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:
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 withgit 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.
对于那些试图排除整个目录时遇到此问题的人:
我刚刚遇到了此问题并且感到非常困惑。我已将目录添加到 .gitignore 中,其中一个文件出现在 git ls-files -o 中。该目录的其他文件显示在 git status 中。
我最终发现我必须以不同的方式对待目录中的文件,因为其中一些文件已经被跟踪,而另一些则没有。所以我只是使用了 git update-index --skip-worktree(就我而言,更好的版本是 git update-index --assume-unchanged,参见此处< /a>) 已跟踪的文件(在
git status
中显示为正在修改的文件)。与在整个目录上调用此命令相比,这很有效,因为我没有尝试排除尚未跟踪且已被 .gitignore 排除的文件。该目录中的其他文件我不必使用此命令排除,因为它们已被 .gitignore 排除。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 ingit 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 ofgit update-index --assume-unchanged <filename>
, see here) on the files that were already tracked (the ones showing up ingit 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.首先,暂存您的文件。然后,仅在此之后,运行
--assume-unchanged
。最后,取消暂存文件。First, stage your file. Then, only after that, run
--assume-unchanged
. Finally, unstage the file.