Git 将重复文件添加到存储库中

Git adding duplicate files into the repo

我的 git 存储库中有一个名为 readme.html 的文件。

它已经存在 10 个月了,还没有碰过它。

今天我处理了其他文件并做了 git add --all,提交并推送了新版本。

readme.html 没有更改,但我有这个名为 readme.4ead5bd97d0927ddb88f8f672067910a.html 的文件。

readme.html内容相同。

如何处理这个问题以及为什么会这样?

某些工具已生成它作为备份或出于某些其他原因。

您可以简单地使用这些命令删除此文件:

# remove and commit the file
rm readme.4ead5bd97d0927ddb88f8f672067910a.html
git rm --cached readme.4ead5bd97d0927ddb88f8f672067910a.html

# just verify that  the file will be deleted
git add -A .
git status

# commit the deletion of the file
git commit -m "Deleted readme.4ead5bd97d0927ddb88f8f672067910a.html"

git push origin <branch>

这与Git无关。您在历史上的某个时间点无意中在 Git 之外创建了该文件,并通过执行 git add --all.

添加了它