在git重置后——很难,git状态给了我在Changes not staging for commit:部分中的文件。

我也试过git reset ., git checkout。而git check - out-index -f -a,毫无用处。

那么,我怎样才能摆脱这些未分阶段的变化呢?

这似乎只影响Visual Studio项目文件。奇怪。请看这个粘贴:http://pastebin.com/eFZwPn9Z。这些文件的特殊之处在于,在.gitattributes中我有:

*.sln        eol=crlf
*.vcproj     eol=crlf
*.vcxproj*   eol=crlf

另外,在我的全局.gitconfig中,selflf被设置为false。这有什么关系吗?


当前回答

我遇到了一个类似的问题,也涉及.gitattributes,但我的案例涉及GitHub的LFS。虽然这并不完全是OP的场景,但我认为它提供了一个机会来说明.gitattributes文件的功能以及为什么它会以“幻影”差异的形式导致未分阶段的更改。

在我的例子中,一个文件已经在我的存储库中,就像从一开始一样。在最近的一次提交中,我添加了一个新的git-lfs跟踪规则,使用的模式事后看来有点太宽泛了,最终匹配了这个古老的文件。我知道我不想改变这个文件;我知道我没有更改文件,但现在它在我的非阶段性更改中,无论对该文件进行多少签出或硬重置都无法修复它。为什么?

GitHub LFS extension works primarily through leveraging the hooks that git provides access through via the .gitattributes file. Generally, entries in .gitattributes specify how matching files should be processed. In the OP's case, it was concerned with normalizing line endings; in mine, it was whether to let LFS handle the file storage. In either case, the actually file that git sees when computing a git diff does not match the file that you see when you inspect the file. Hence, if you change how a file is processed via the .gitattributes pattern that matches it, it will show up as unstaged changes in the status report, even if there really is no change in the file.

综上所述,我对这个问题的“回答”是,如果.gitattributes文件中的更改是您想要做的,那么您应该只添加更改并继续前进。如果不是,那么修改.gitattributes以更好地表示您想要做的事情。

参考文献

GitHub LFS规范-很好地描述了它们如何钩子到clean和smudge函数调用中,用一个带散列的简单文本文件替换git对象中的文件。 gitattributes文档——所有可用于自定义git如何处理文档的细节。

其他回答

在类似的情况下。由于多年来与许多程序员的折磨,他们能够填充行尾的不同编码(.asp, .js, .css…不是精华)放入一个文件。前段时间拒绝了.gitattributes。repo left的设置autorclf = true和safecrlf = warn。

最后一个问题出现在从具有不同行尾的存档进行同步时。从存档中复制后,在git状态下许多文件都随注释而改变

在您的工作目录中,该行将有其原始的行结束符。 警告:在…中将由CRLF取代LF

如何在Git中规范化工作树行结束?帮助

Git add -u

我也有同样的问题。我做了git重置-硬头,但仍然每次我做git状态,我看到一些文件被修改。

我的解决办法相对简单。 我只是关闭我的IDE(这里是Xcode),关闭我的命令行(这里是我的Mac OS上的终端),再试一次,它工作了。

然而,我始终无法找到问题的根源。

执行clean命令:

# Remove all untracked files and directories. (`-f` is `force`, `-d` is `remove directories`)

git clean -fd

出于某种原因

转到添加 。

没用,但是

$ git添加

工作了!

我已经通过以下步骤解决了这个问题

从Git的索引中删除每个文件。 Git rm——cached -r。 重写Git索引以获取所有新的行结束符。 Git重置——很难

解决方案是配置Git处理行结束部分描述的步骤的一部分