我怎么做
git状态
忽略行结束差异?
背景信息:
我随机使用Windows和Linux来处理这个项目。 该项目在Dropbox中。
我发现很多关于如何使git diff忽略行结尾。 由于我使用融合git diff打开每个文件的meld。 而融合说“相同的文件”。
那么我该如何避免呢? Git只能打开已更改文件的组合。 如果只有文件结尾是不同的,那么git状态不应该报告被更改的文件。
编辑:原因:
这是因为Windows上的这个设置
core.autocrlf true
所以我检查了Linux上的工作副本,并在Windows上设置core.autocrlf false。
知道如何让git状态忽略不同的新行,这将是很好的。
使用.gitattributes代替以下设置:
# Ignore all differences in line endings * -crlf
.gitattributes将在您的全球.gitconfig相同的目录中找到。 如果.gitattributes不存在,请将其添加到该目录。 在添加/更改.gitattributes之后,您必须对存储库进行硬重置,才能成功将更改应用到现有文件。
试试像这样设置core.autocrlf值:
git config --global core.autocrlf true
我同时使用Windows和Linux,但解决方案core.autocrlf true
没有帮助我。 git checkout <filename>
后,我什至没有改变。
所以我使用替代方法git status
– gitstatus.sh
#!/bin/bash git status | grep modified | cut -d' ' -f 4 | while read x; do x1="$(git show HEAD:$x | md5sum | cut -d' ' -f 1 )" x2="$(cat $x | md5sum | cut -d' ' -f 1 )" if [ "$x1" != "$x2" ]; then echo "$x NOT IDENTICAL" fi done
我只是比较一个文件的md5sum
和它在存储库中的兄弟。
示例输出:
$ ./gitstatus.sh application/script.php NOT IDENTICAL application/storage/logs/laravel.log NOT IDENTICAL
我创建了一个脚本来忽略行尾的差异:
它将显示没有添加到提交列表中并被修改的文件(在忽略行尾的差异之后)。 您可以添加参数“添加”将这些文件添加到您的提交。
#!/usr/bin/perl # Usage: ./gitdiff.pl [add] # add : add modified files to git use warnings; use strict; my ($auto_add) = @ARGV; if(!defined $auto_add) { $auto_add = ""; } my @mods = `git status --porcelain 2>/dev/null | grep '^ M ' | cut -c4-`; chomp(@mods); for my $mod (@mods) { my $diff = `git diff -b $mod 2>/dev/null`; if($diff) { print $mod."\n"; if($auto_add eq "add") { `git add $mod 2>/dev/null`; } } }
源代码: https : //github.com/lepe/scripts/blob/master/gitdiff.pl
更新 :