How to get diff working like git-diff?

前端 未结 14 2228
慢半拍i
慢半拍i 2020-12-12 10:42

I like the output formatting of git diff. The color and the +/- representation of changes between lines is easier to read than GNU di

相关标签:
14条回答
  • 2020-12-12 11:07
    1. Install colordiff.

    2. Update your ~/.colordiffrc (copying /etc/colordiffrc first, if necessary):

      # be more git-like:
      plain=off
      newtext=darkgreen
      oldtext=darkred
      diffstuff=darkcyan
      
    3. Use colordiff -u file1 file2 for two files or colordiff -ruN path1 path2 for recursively comparing paths.

    It's not exactly the same, but it's very close.

    0 讨论(0)
  • 2020-12-12 11:07

    Use colordiff:

    Installation:

    sudo apt-get install colordiff
    

    Usage:

    colordiff -u file_one file_two
    

    Gives exactly same difference as shown by git diff.

    0 讨论(0)
  • 2020-12-12 11:11

    If you don't have colordiff or git diff, you can get color by vim.

    cdiff() { diff -u $@ | vim -R -; }
    

    or simply

    cdiff() { diff -u $@ | view -; }
    
    0 讨论(0)
  • 2020-12-12 11:11

    Tested in debian 9 diff -u --color=always file1 file2

    0 讨论(0)
  • 2020-12-12 11:15

    Place this in your .bashrc or .zshrc :

    diff() { git diff --no-index "$1" "$2" | colordiff; }

    requirments : git and colordiff should be installed before-hand.

    usage : diff file1 file2

    example : for $diff .tmux.conf .zshrc.pre-oh-my-zsh

    0 讨论(0)
  • 2020-12-12 11:18

    You can also use git diff --no-index -- A B (via manpage).

    0 讨论(0)
提交回复
热议问题