Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format the output of git diff

Tags:

git

Is it possible to format the output of git diff so I'll get only the actual text difference?

for example, this is the default git diff output:

diff --git a/diff_test.txt b/diff_test.txt
index 6b0c6cf..b37e70a 100644
--- a/diff_test.txt
+++ b/diff_test.txt
@@ -1 +1 @@
-this is a git diff test example
+this is a diff example

Instead I want to get:

diff --git a/diff_test.txt b/diff_test.txt
-this is a git diff test example
+this is a diff example

is it possible with git diff or other git command without using other scripts like shell, python ,etc?

like image 776
Tidhar Klein Orbach Avatar asked Oct 29 '25 21:10

Tidhar Klein Orbach


1 Answers

Excluding a diff patch header involves generally shell commands (tail/sed)

You can only limit the context to only the modified line, but anything more, like hiding/remove the hunk headers, as in this answer, will involve some "non-git" command.

like image 52
VonC Avatar answered Oct 31 '25 12:10

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!