Git CRLF更改显示为git状态 [英] Git CRLF changes showing up in git status

查看:463
本文介绍了Git CRLF更改显示为git状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多类似这个问题的问题/答案,但是我找不到这个问题的具体答案。我们是.net商店,正在使用git。



我想在执行git状态时忽略CRLF(^ M)文件更改的方法。在开发过程中,其他进程偶尔会修改文件并注入CRLF,最终导致它们在完成git状态时显示为已修改。我的.gitattributes文件中有* text = auto行,以便在结帐/提交时对行结束进行标准化,但这不是我正在寻找的。我也尝试添加以下到git config(core.whitespace = cr-at-eol),但它们仍显示为已修改。



如何让git忽略对CRLF(^ M)的所有更改?

解决方案

您不能忽略 git status 的文件变更类型。您可以使用 .gitignore 忽略整个文件。您可以使用各种空白选项来转换提交内容,突出显示内容(红色)或在差异视图和提交视图中显示。



不能忽略这些文件变化的原因是:



总之,您可能需要修复其他进程或开发清理后期处理。或者你可以使用:

  git diff-files --name-status --ignore-space-at-eol 

这不是状态的完美模拟,但它可能足以满足您的需求需要。为了方便起见,您甚至可以通过添加 .gitconfig 来构建 git-alias 'dstatusx命令:

  [别名] 
statusx = diff-files --name-status --ignore-space-at-eol

如果证明不足,还有一些额外的空格选项: - ignore-space-change - ignore-all-space 。有关更多详细信息,请参阅 git diff --help


I know there are a ton of questions/answers similar to this one, however I could not find a specific answer to this problem. We are a .net shop and are using git.

I would like a way to ignore CRLF (^M) changes to files when doing a git status. While developing, other processes are occasionally modify files and injecting the CRLF, ultimately resulting in them showing as modified when a git status is done. I have the line "* text=auto" within my .gitattributes file in order to normalize line endings at checkout/commit but this is not what I am looking for. I have also tried to add the following to the git config (core.whitespace=cr-at-eol) but they still show as modified.

How do I tell git to ignore all changes to CRLF (^M)?

解决方案

You cannot ignore types of filechanges for git status. You can use .gitignore to ignore entire files. And you can use the various whitespace options to transform what is committed, what is highlighted (in red) or shown at all in the diff and commit views.

The reasons you cannot ignore these filechanges are:

  • Tracking filechanges is the entire point of version control.
  • Git represents file contents independent of path by using a SHA1 hash of the contents. Your ^M affects that SHA1 so that makes it unavoidably significant.

In short, you probably need to fix your other processes or develop clean-up post-processes. Alternatively you could use:

git diff-files --name-status --ignore-space-at-eol

This is not a perfect analogue of status proper, but it might be enough for your needs. For convenience, you can even build a git-alias'd "statusx" command by adding to your .gitconfig:

[alias]
    statusx = diff-files --name-status --ignore-space-at-eol

There are some additional whitespace options if that proves inadequate: --ignore-space-change and --ignore-all-space. See git diff --help for more detail.

这篇关于Git CRLF更改显示为git状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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