我想删除对我的工作副本的所有更改。 运行git状态显示已修改的文件。 我所做的一切似乎都无法消除这些修改。 例如:

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ 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:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git checkout -- Rhino.Etl.Core/Enumerables/CachingEnumerable.cs

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ 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:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git checkout `git ls-files -m`

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ 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:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git reset --hard HEAD
HEAD is now at 6c857e7 boo libraries updated to 2.0.9.2 and rhino.dsl.dll updated.

rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ 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:   Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
#       modified:   Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
#       modified:   Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
#       modified:   Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")

当前回答

试着做一个

Git checkout -f

这将清除当前工作的本地回购中的所有更改

其他回答

如果克隆存储库并立即看到挂起的更改,则存储库处于不一致状态。请不要从.gitattributes文件中注释掉* text=auto。这是专门放在那里的,因为存储库的所有者希望所有文件都以LF行结束符一致存储。

正如HankCa所述,按照https://help.github.com/articles/dealing-with-line-endings/上的说明来解决问题。简单的按钮:

git clone git@host:repo-name
git checkout -b normalize-line-endings
git add .
git commit -m "Normalize line endings"
git push
git push -u origin normalize-line-endings

然后将分支合并(或拉取请求)到回购的所有者。

我在Windows上遇到了这个问题,但还没有准备好研究使用配置全局核心的后果。我也不准备放弃我的其他私人分支和好东西,开始一个新的克隆。我只是需要做点事。现在。

这对我来说是可行的,因为你让git完全重写你的工作目录:

git rm --cached -r .
git reset --hard

(请注意,仅仅运行git reset -hard不够好,在重置之前对文件进行简单的rm也不够好,就像对原始问题的评论中建议的那样)

一个建议的解决方案在这里没有工作,我发现文件实际上是一个链接到一些特殊字符:

% ls -l StoreLogo.png
lrwxrwxrwx 1 janus janus 8 Feb 21 10:37 StoreLogo.png -> ''$'\211''PNG'$'\r\n\032\n'

% git status    
Changes not staged for commit:
    modified:   StoreLogo.png

% git rm --cached -r StoreLogo.png
rm 'src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png'

% git reset StoreLogo.png         
Unstaged changes after reset:
M   src/GWallet.Frontend.XF.UWP/Assets/StoreLogo.png

% git status                      
Changes not staged for commit:
    modified:   StoreLogo.png

我遇到的问题是,windows不关心文件名大写,但git关心。因此git存储了文件的小写和大写版本,但只能签出其中一个。

我也有同样的症状,但是由不同的原因引起的。

我没能:

git checkout app.js //did nothing
git rm app.js //did nothing
rm -rf app.js //did nothing

即使在 git rm——缓存app.js,它的签名为删除,在未跟踪的文件中,我可以看到app.js。但是当我尝试rm -rf app.js并再次执行git状态时,它仍然显示我的文件处于“untracked”状态。

经过同事的几次尝试,我们发现,这是由Grunt引起的!

由于Grunt已经打开,并且因为app.js已经从其他几个js文件中生成,我们发现在每次使用js文件(也是这个app.js)的操作之后,Grunt再次重新创建app.js。