为什么Git坚持认为即使在`git checkout --`之后文件已被修改? [英] Why does Git insist that a file has been modified even after a `git checkout --`?
问题描述
我在本地对一些文件进行了更改,没有提交它们。 git status
显示:
>> git status
#在分支上feature-ravendb
#你的分支在1次提交之前在'origin / feature-ravendb'之前。
#
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git
#
#modified:source / Octopus.Tentacle / Integration / PowerShell / IPowerShell.cs
#修改:< file> source / Octopus.Tentacle / Integration / PowerShell / PowerShellRunner.cs
#
没有更改添加到提交中(使用git add和/或git commit -a)
我想放弃对这些文件的更改。我尝试了以下指示:
>> git checkout - .\source\Octopus.Tentacle\Integration\PowerShell\IPowerShell.cs
该命令没有输出。现在我再次执行 git status
:
pre $ >> git status
#在分支上feature-ravendb
#你的分支在1次提交之前在'origin / feature-ravendb'之前。
#
#没有为commit提交更改:
#(使用git add< file> ...更新将提交的内容)
#(使用git
#
#modified:source / Octopus.Tentacle / Integration / PowerShell / IPowerShell.cs
#修改:< file> source / Octopus.Tentacle / Integration / PowerShell / PowerShellRunner.c
#
没有更改添加到提交中(使用git add和/或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>使用系统;
-
--namespace Octopus.Tentacle.Integration.PowerShell
- {
- public interface IPowerShell
- {
- PowerShellExecutionResult Execute(PowerShellArguments arguments);
- }
+< EF>< BB>< BF>使用系统;
+
+ namespace Octopus.Tentacle.Integration.PowerShell
+ {
+ public interface IPowerShell
+ {
+ PowerShellExecutionResult Execute(PowerShellArguments arguments);
+}
}
\不在文件结尾换行
我如何说服git,我确实没有改变过这个文件,也不想提交它?
编辑:以下命令对这些修改也具有无效:
-
git checkout - 。
-
git checkout -f
-
git reset --soft
git reset --hard
编辑2 :恢复到旧版本,存储我的更改,然后清除最终可用的存储。这似乎是我的行结束冲突,但我不知道为什么:
core.autocrlf
设为true
.gitattributes
文件,其中 *这行。 cs text
这不够吗?
我有一个core.autocrlf是错误的,但最近更改为true,并对.net应用gitattributes更改。之后,在许多存储库中,当您尝试拉时,我开始接收不存在的更改的报告,并且也无法回滚。最后,我回到了core.autocrlf为false
I made a change to a couple of files locally, without committing them. git status
shows:
>> 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")
I want to discard the changes to those files. I tried following the instructions:
>> git checkout -- .\source\Octopus.Tentacle\Integration\PowerShell\IPowerShell.cs
The command has no output. Now I run git status
again:
>> 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")
Hmm, it's pretty convinced that the file has changed. And git diff <file>
seems to think that the whole file has changed, even though it hasn't:
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
How do I convince git that I really, really haven't changed the file and don't want to commit it?
Edit: The following commands also have no effect on these modifications:
git checkout -- .
git checkout -f
git reset --soft
git reset --hard
Edit 2: Reverting back to an older revision, stashing my changes, then clearing the stash eventually worked. It seems like my line endings are conflicting but I don't know why:
- I have
core.autocrlf
set to true - I have a
.gitattributes
file with the line*.cs text
Shouldn't this be enough?
I had a core.autocrlf is false, but recently changed to true and also apply gitattributes changes for .net. After that, in many repositories, when you try to pull, I began to receive reports on the changes which not exist, and are also unable to roll back. In the end, I went back to core.autocrlf is false
这篇关于为什么Git坚持认为即使在`git checkout --`之后文件已被修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!