我遇到了一种奇怪的情况,在我的一个分支中,无法将 web.config 文件添加到舞台上。的输出
git add path/to/web.config
git status
与添加文件之前相同。 Web.config 似乎需要修改并且尚未添加到阶段。
也许更有趣的是,当我从文件系统中删除 Web.config 并运行 git status
时我得到的输出表明我有 两个 web.config 文件可以删除并且没有暂存。
# Changes not staged for commit:
# deleted: path/to/Web.config
# deleted: path/to/web.config
请注意,一个是大写的 W,另一个是小写的 w。我在实际文件系统上删除的文件是大写的“W”。
编辑 1
git ls-files --stage
的输出显示索引中确实有两个大小写不同的文件。
100644 63cd5911b9b12bbad559bb69b1b596708b932061 0 path/to/Web.config
100644 d60ab44bb38f05ffce126ddd3c3293b06e6e4096 0 path/to/web.config
我用 git cat-file -p <hash> > <file>
将每一个输出到一个文件中并比较了两个文件。虽然文本内容相同,但大写的 Web.config 包含 CRLF 结尾,而小写的 web.config 包含小写结尾。
编辑2
从文件系统中物理删除文件git reset HEAD
产生此输出,但文件未在文件系统上恢复,因此无法添加。
Unstaged changes after reset
D path/to/Web.config
D path/to/web.config
我希望工作目录中的文件具有 CRLF,因为我在 Windows 上工作,但我希望文本文件以 LF 存储在内部 Git 数据库中。所以,我假设那将是 63cd591,但我可能在这里偏离了基准。
在这种情况下,如何从索引中永久删除 path/to/web.config?我在 Windows 上,我的路径上不能有两个仅大小写不同的文件。
最佳答案
这个特定问题的最终解决方案是从 git 缓存中删除两个 web.config 条目,提交所有更改,然后将所需的 Web.config 文件重新添加回 git。
git rm --cached path/to/Web.config
git rm --cached path/to/web.config
git commit -m "Repair confused cache"
git add path/to/Web.config
git commit -m "Add Web.config"
关于git - 将文件添加到 git 的阶段没有任何作用,也无法提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17798583/