如果文件被识别为未更改,如何强制 Git 提交文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22666606/
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 09:53:56  来源:igfitidea点击:

How to force Git to commit a file if it is recognized as unchanged

git

提问by ToBe

I have 2 binary files, which have

我有 2 个二进制文件,其中有

  • exactly same size
  • exactly same modification date
  • exactly same creation date
  • 完全一样的大小
  • 完全相同的修改日期
  • 完全相同的创建日期

but

  • different content
  • 不同的内容

If I replace one file with the other, git does not recognize this file as changed.

如果我用另一个文件替换一个文件,git 不会将此文件识别为已更改。

Filesystem: NTFS, OS: Windows 7, Git Version: 1.9.0

文件系统:NTFS,操作系统:Windows 7,Git 版本:1.9.0

(my workaround is to edit this new file to get a new modification date but I keep same content)

(我的解决方法是编辑这个新文件以获得新的修改日期,但我保留相同的内容)

How can I force Git to commit the new file?

如何强制 Git 提交新文件?

回答by user3426575

You could always do

你总能做到

git rm --cached <file>
git add <file>

This should put the new file into the index regardless of what was previously there.

这应该将新文件放入索引中,而不管之前有什么。

回答by user3426575

Maybe you accidentally set the “assume unchanged” bit for the file's path.

也许您不小心为文件路径设置了“假设不变”位。

When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file.

当“假设未更改”位打开时,Git 将停止检查工作树文件以进行可能的修改,因此您需要手动取消设置该位以在您更改工作树文件时通知 Git。

To unset the “assume unchanged” bit, type:

要取消设置“假设不变”位,请键入:

git update-index --no-assume-unchanged <file>