Git:如何恢复2个顽固地停留在“更改但未提交”的文件? [英] Git: How to revert 2 files that are stubbornly stuck at "Changed but not committed"?

查看:158
本文介绍了Git:如何恢复2个顽固地停留在“更改但未提交”的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以我坚持这样做:


$ b我有一个回购有两个文件,据说我本地改变了。 $ b

  $ git status 
#分支主
#已更改但未更新:
#(使用git add< file> ;. ..来更新将提交的内容)
#(使用git checkout - < file> ...放弃工作目录中的更改)

#修改:dir1 /foo.aspx
#modified:dir2 / foo.aspx

没有更改添加到提交中(使用git add和/或git commit -a)



表示整个文件内容已经改变,即使从眼睛看来,这似乎是不真实的(似乎差异似乎没有看到共同的线条范围)。



有趣的是,我不记得改变这些文件本地。这个回购是用于一个远程回购(私人,在GitHub.com,FWIW)。

无论我尝试了什么,我都不能放弃这些本地更改。我已经尝试了所有:

  $ git checkout  - 。 
$ git checkout -f
$ git checkout - dir1 / checkout_receipt.aspx
$ git reset --hard HEAD
$ git stash save --keep-index&& amp ; git stash drop
$ git checkout-index -a -f

换句话说,已经尝试了中描述的所有内容。我该如何放弃Git中未分离的更改?>加更多。但是这两个文件仍然停留在已更改但未提交的状态。



到底是什么让两个文件卡住了这个样子,看起来像是un-revert-table ??



PS在上面显示的命令列表中,我已经尝试过了,当我的意思是 git checkout 时,我错误地写了 git revert 。我很抱歉,并且对那些回答我应该尝试 checkout 的人表示感谢。我编辑了这个问题来纠正它。我确实已经尝试过 checkout

解决方案

在文件中?我打赌他们是CRLF。如果是,请查看本指南: http://help.github.com/line-endings/

总之,您需要确保git设置为在提交时将行结束符转换为LF,然后提交这些文件。假设您正确设置了git,回购库中的文件应始终为LF,检出的文件应为操作系统的本地文件。


I have a repo that has two files that supposedly I changed locally.

So I'm stuck with this:

$ 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:   dir1/foo.aspx
#       modified:   dir2/foo.aspx
#
no changes added to commit (use "git add" and/or "git commit -a")

Doing git diff says that the entire file contents have changed, even though from eyeballing it that seems untrue (there seem to be common line ranges that diff seems to be failing to see).

Interestingly I don't remember changing these files locally. This repo is used with one remote repo (private, at GitHub.com, FWIW).

No matter what I've tried, I can't discard these local changes. I have tried all of:

$ git checkout -- .
$ git checkout -f
$ git checkout -- dir1/checkout_receipt.aspx
$ git reset --hard HEAD
$ git stash save --keep-index && git stash drop
$ git checkout-index -a -f

In other words I've tried everything described in How do I discard unstaged changes in Git? plus more. But the 2 files remain stuck as "changed but not committed".

What the heck would cause two files to be stuck like this and seemingly "un-revert-table"??

P.S. In the list above showing commands I'd already tried, I mistakenly wrote git revert when I meant git checkout. I'm sorry and thank you to those of you who answered that I should try checkout. I edited the question to correct it. I definitely did already try checkout.

解决方案

What are the line endings in the files? I'm betting they're CRLF. If they are, check out this guide: http://help.github.com/line-endings/

In short, you need to make sure git is set to convert the line endings to LF on commit, and then commit those files. Files in the repo should always be LF, files checked out should be the OS's native, assuming you set git correctly.

这篇关于Git:如何恢复2个顽固地停留在“更改但未提交”的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆