4

我在本地对几个文件进行了更改,但没有提交它们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设置为真
  • 我有一个.gitattributes文件与该行*.cs text

这还不够吗?

4

1 回答 1

4

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

于 2012-04-04T19:51:30.660 回答