【问题标题】:Why do I still have "Changed but not updated" files?为什么我仍然有“已更改但未更新”的文件?
【发布时间】:2014-10-23 14:44:10
【问题描述】:

我有一个修改过的文件:

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   vw_static.vcxproj
#

即使在git reset --hardgit checkout -- vw_static.vcxproj 之后。

git diff 似乎仅表示空白(特别是行终止)差异。

$ git config core.autocrlf
input
$ git config --global core.autocrlf
input

此项目中没有.git/info/attributes(也没有全局.gitattributes)。

我不关心这个项目中的行尾,我对更改这个特定文件不感兴趣(尤其是提交与它相关的任何内容)。

我想要的只是 git status 报告树未修改。

我如何得到它?

【问题讨论】:

标签: git


【解决方案1】:

这些文件可能是以 DOS 行结尾的 repo 提交的。试试这个:

git config core.autocrlf false
rm .git/index
git reset --hard
dos2unix file1
dos2unix file2
git commit -m "Ensure files are commited with Unix line endings" file1 file2
git config core.autocrlf input
git status

【讨论】:

  • 有很多方法不涉及提交。
  • 如果文件已经以 DOS 行结尾提交到 repo,则不会。在这种情况下,它们是“损坏的”,需要“修复”。
【解决方案2】:

这里是 linux 的答案:

git config --global core.autocrlf true && git checkout -- vowpalwabbit/vw_static.vcxproj && git status

事实上,要独立于平台,我必须这样做:

for opt in true false input; do
  git config --global core.autocrlf $opt
  for f in $(git ls-files -m); do
    git checkout -- $f
  done
  git status
done

PS。我知道这个“解决方案”很糟糕,但我需要的只是一个变通方法。我确实拥有该回购协议,并且我无法引入重大更改。

【讨论】:

  • 在 Linux 上设置 core.autocrlf true 只是掩盖了文件以 DOS 行以 repo 结尾的事实,而它们不应该。无论如何,使用core.autocrlfdeprecated 支持.gitattributes。您应该在right way 中执行此操作并规范化所有文件以在 repo 中使用 Unix 行结尾,并使用带有*.vcxproj text eol=crlf.gitattributes 文件来检查这些文件在 all上的 DOS 行结尾> 平台。
  • @sschuberth:正如我在问题中所说,我确实拥有该回购协议。我所需要的只是使文件保持不变。
  • 对不起,我错过了。
  • 我是,由于误解,我试图撤消它,但我的反对票现在被锁定,直到您编辑帖子。如果您愿意,请进行虚拟编辑,然后我将撤消我的反对票。
猜你喜欢
  • 2021-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 2013-10-10
  • 1970-01-01
  • 2016-02-04
  • 1970-01-01
相关资源
最近更新 更多