How do I exclude the patch header with "git diff"?

Viewed 3726

For example in the below output of git diff

diff --git a/commands.txt b/commands.txt
index 79e881a..a9588e5 100644
--- a/commands.txt
+++ b/commands.txt
@@ -1,3 +1,7 @@
+this is an example
+abcxyz
+helllo
+wooo
 makeFilePermissionExecutable
 makeOwnedByMyself
 makeFilePermissionEverything

Is it possible to hide the following:

diff --git a/commands.txt b/commands.txt
index 79e881a..a9588e5 100644
--- a/commands.txt
+++ b/commands.txt

And instead just show the filename (commands.txt in this case) instead?

3 Answers

git diff | tail -n +5 will produce the output that you desire.

We pipe the output of git diff into tail -n +5 to begin output on line 5. See the man page for tail -n:

   -n, --lines=[+]NUM
          output the last NUM lines, instead of the last  10;  or  use  -n
          +NUM to output starting with line NUM

You'll have to do some additional regex work if you're looking to consolidate --- a/commands.txt and +++ b/commands.txt to a single line.

Related