似乎无法放弃Git中的更改 [英] Can't seem to discard changes in Git

查看:119
本文介绍了似乎无法放弃Git中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从命令行看到以下内容:

 #分支RB_3.0.10 
#已更改,但未更新:
#(使用git add< file> ...更新将要提交的内容)
#(使用git checkout - < file> ...放弃更改在工作目录中)

#修改:index.htm

我是试图通过键入命令来放弃我的更改:

  git checkout  -  index.htm 

但是当我重新运行git status时,它看起来完全一样。结帐似乎没有工作。难道我做错了什么?我在windows / cygwin上使用GIT 1.6.1.2。

 #分支RB_3.0.10 
#已更改,但未更新:
#(使用git add< file> ...更新将要提交的内容)
#(使用git checkout - < file> ...放弃更改在工作目录中)

#modified:index.htm


解决方案

文件上显示 git diff 哪些更改?在Windows上,我看到了线结束的问题,导致这样的问题。在这种情况下,请查看您为 git config core.autocrlf git config core.safecrlf 设置了哪些设置。这里有一些这些设置的文档



我会说,如果你使用 git svn 与颠覆集成,那么做确定 autocrlf 已关闭。从我可以告诉它只是在这个配置中被破坏,并且当你完成 checkout 来还原任何改变时,它使大多数工具认为文件已被改变。 / p>

如果您在执行 git checkout ,然后 git status 显示文件仍然被修改,并且 git diff 显示文件在文件的每一行被修改,那么这就是你所看到的问题。


core.autocrlf

如果为true,则在最后使用git convert CRLF将文本文件中的行从文件系统中读取到LF
时,
在写入
文件系统时反向转换。该变量可以设置为
输入,在这种情况下,转换
仅在从
文件系统读取时发生,但文件在行尾以LF写出

目前,考虑
text(即受制于
autocrlf机制)的路径根据内容纯粹由
决定。



core.safecrlf

如果为true,则使git检查是否可以转换由
core.autocrlf控制的CRLF。 Git将
验证命令是否直接修改
中的文件或直接修改
中的文件。例如,提交
文件,然后检出相同的
文件,应该在
工作树中产生原始文件。如果当前
core.autocrlf的设置不是
,那么git会拒绝
文件。变量可以设置为
warn,在这种情况下,git只会对
发出不可逆转换
的警告,但会继续操作。
...



After seeing the following from the command line:

# On branch RB_3.0.10
# 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:   index.htm

I am trying to discard my changes by typing the command:

git checkout -- index.htm

but when I re-run git status, it looks exactly the same. The checkout doesn't seem to be working. Am I doing something wrong? I am using GIT 1.6.1.2 on windows/cygwin.

# On branch RB_3.0.10
# 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:   index.htm

解决方案

What changes does git diff show on the file? On windows, I've seen issues with line-endings causing issues like this. In that case, look at what settings you have for git config core.autocrlf and git config core.safecrlf. There is some documentation for these settings here.

I would say, if you are using git svn for integration with subversion, then do make sure autocrlf is turned off. From what I can tell it is just broken in this configuration and it makes most of the tools think files have been changed, when you have done a checkout to revert any changes.

If you are seeing a problem where you do git checkout, and then git status shows the file is still modified, and git diff shows the file is modified on every line in the file, then this is the problem you are seeing.

core.autocrlf

If true, makes git convert CRLF at the end of lines in text files to LF when reading from the filesystem, and convert in reverse when writing to the filesystem. The variable can be set to input, in which case the conversion happens only while reading from the filesystem but files are written out with LF at the end of lines. Currently, which paths to consider "text" (i.e. be subjected to the autocrlf mechanism) is decided purely based on the contents.

core.safecrlf

If true, makes git check if converting CRLF as controlled by core.autocrlf is reversible. Git will verify if a command modifies a file in the work tree either directly or indirectly. For example, committing a file followed by checking out the same file should yield the original file in the work tree. If this is not the case for the current setting of core.autocrlf, git will reject the file. The variable can be set to "warn", in which case git will only warn about an irreversible conversion but continue the operation. ...

这篇关于似乎无法放弃Git中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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