git diff dictate extra blank line between files

Solution 1:

Here is an answer using sed and bash/zsh (as answered here) :

# include a '\' followed by a linefeed ('\n') in the replace pattern of sed :
git diff --cached | sed -e 's/^diff --git/'$'\\\ndiff --git/'

(note: the bash/zsh specific part of the command above lies in the syntax used to insert an actual \<lf> on the command line : $'\\\n' will translate to that in bash/zsh, but perhaps not in other shells -- e.g : cmd.exe or powershell. You may choose another way to insert a \<lf> in a sed pattern, for example by reading patterns from a file instead of the command line, or by choosing a shell specific way to insert those characters on the command line)


If you want to keep the colors displayed by git diff, one way to do so is :

git diff --cached --color=always |\
    # spot the escape sequence that sets "diff --git" in bold, and print it in the output
    sed -e 's/^\(..1m\)diff --git/'$'\\\n\\1diff --git/'