Git status ignore line endings / identical files / windows & linux environment / dropbox / mled

后端 未结 6 1832
离开以前
离开以前 2020-12-02 07:42

How do I make

git status

ignore line ending differences?

Background info:

I use randomly Windows and Linux to w

6条回答
  •  情书的邮戳
    2020-12-02 08:10

    I created a script to ignore differences in line endings:

    It will display the files which are not added to the commit list and were modified (after ignoring differences in line endings). You can add the argument "add" to add those files to your commit.

    #!/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`;
            }
        }
    }
    

    Source code: https://github.com/lepe/scripts/blob/master/gitdiff.pl

    Updates:

    • fix by evandro777 : When the file has space in filename or directory

提交回复
热议问题