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?
Git diff is a command used to output the changes between two sources inside the git repository. The data sources can be two different branches, commits, files, etc.
When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.
Use ONLY q+enter to exit. It's possible to break out by repeatedly typing q+enter+q+enter+q+enter until the end of time no matter what the console shows.
You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.
A workaround I found:
Make the following file accessible in your PATH:
customGitDiff
#!/usr/bin/env bash
echo "$(tput setaf 4) $1"
echo -n "$(tput setaf 4)"
printf "%$(tput cols)s"|tr ' ' '-'
diff -u "$1" "$2" | tail -n +3 | colordiff
echo ""
Then you can instruct git to use the following script as your diff tool. It can be globally set by setting the following in your ~/.gitconfig
:
[diff]
external = customGitDiff
One possibly unfortunate limitation of this, is I'm not sure if it uses the same diff algorithm as git diff.
The above provides me with the following output:
git diff etc \
| sed '/^diff /,/^@@/ {
H;/^@@/!d;z;x
s".*\n--- a/\([^\n]*.\)+++ b/\1"==> File: \1"
}
'
That's "accumulate all lines in blocks starting ^diff
and ending ^@@
, and if the file isn't new reformat the header".
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With