为什么Git坚持文件已被修改,即使在`git checkout --`之后?

时间:2012-04-04 19:23:14

标签: git line-endings

我在本地修改了几个文件,没有提交git status显示:

>> git status
# On branch feature-ravendb
# Your branch is ahead of 'origin/feature-ravendb' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/PowerShellRunner.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

我想放弃对这些文件的更改。我尝试按照说明操作:

>> git checkout -- .\source\Octopus.Tentacle\Integration\PowerShell\IPowerShell.cs

该命令没有输出。现在我再次运行git status

>> git status
# On branch feature-ravendb
# Your branch is ahead of 'origin/feature-ravendb' by 1 commit.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
#       modified:   source/Octopus.Tentacle/Integration/PowerShell/PowerShellRunner.c
#
no changes added to commit (use "git add" and/or "git commit -a")
嗯,它确信文件已经改变了。 git diff <file>似乎认为整个文件已经改变,即使它没有:

diff --git a/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs b/source/Octo
--- a/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
+++ b/source/Octopus.Tentacle/Integration/PowerShell/IPowerShell.cs
@@ -1,9 +1,9 @@
-<EF><BB><BF>using System;
-
-namespace Octopus.Tentacle.Integration.PowerShell
-{
-    public interface IPowerShell
-    {
-        PowerShellExecutionResult Execute(PowerShellArguments arguments);
-    }
+<EF><BB><BF>using System;
+
+namespace Octopus.Tentacle.Integration.PowerShell
+{
+    public interface IPowerShell
+    {
+        PowerShellExecutionResult Execute(PowerShellArguments arguments);
+    }
 }
\ No newline at end of file

我如何说服git我真的,真的没有更改文件而不想提交它?

修改:以下命令对这些修改也有无影响

  • git checkout -- .
  • git checkout -f
  • git reset --soft
  • git reset --hard

编辑2 :恢复旧版本,隐藏我的更改,然后清除存储最终有效。看起来我的行结尾是矛盾的,但我不知道为什么:

  • 我将core.autocrlf设置为true
  • 我有一个.gitattributes文件,其中包含*.cs text

这不应该足够吗?

1 个答案:

答案 0 :(得分:4)

我有一个core.autocrlf是false,但最近更改为true并且还对.net应用gitattributes更改。之后,在许多存储库中,当您尝试拉动时,我开始收到有关不存在的更改的报告,并且也无法回滚。最后,我回到了core.autocrlf是假的