1
diff --git a/sample.py b/sample.py
index ce490c6..2e069ee 100644
--- a/sample.py
+++ b/sample.py
@@ -1,4 +1,6 @@
print("Hello world")
print("Sample project")
print("git log issue")
-print("git log issue demo")
\ No newline at end of file
+print("git log issue demo")
+print("different changes in log")
+print("sample git issues")

I want to remove the first four lines from git logs, which tells about the metadata of diff.

SwissCodeMen
  • 4,222
  • 8
  • 24
  • 34
  • 1
    Does this answer your question? [Print a file, skipping the first X lines, in Bash](https://stackoverflow.com/questions/604864/print-a-file-skipping-the-first-x-lines-in-bash) – Joe May 10 '21 at 11:55

2 Answers2

1

You can easily do it with sed. You can use, git diff | sed -n '5,$p' or more generally
git diff | sed -n 'm,$p'

This means that you are saying sed to print from the mth line to the last line of the file and -n is to suppress automatic printing of pattern space.

Akash Tadwai
  • 100
  • 1
  • 9
1

There's a ton of text-munging tools, if you want to preserve the colorization you have to tell them what to look for, here's one that doesn't rely on the specific count but just strips everything between the diff and the @@.

(If you're new to regexes they can be daunting but the barf code below parses out as \x1b[^m]*m matches a color escape in otherwise plain text, the ^()* around it says any number of what's in the parens at the start of a line, so ^(\x1b[^m]*m)* matches any number of color escapes at the start of a line.)

git log --color=always -p \
| sed -E '/^(\x1b[^m]*m)*diff/,/^(\x1b[^m]*m)*@@/ {//!d}'

Which stripping the color processing from would make the code more and the results less pleasant to read,

git log -p  --color=never -p \
| sed -E '/^diff/,/^@@/ {//!d}'

In sed, // says "search again for the last pattern you searched for", and in a pattern-bounded range on the first line that starts out as the first-line pattern, on all subsequent lines starts out as the last-line pattern. So //!d as a pattern range command deletes everything that's not the first or last lines.

jthill
  • 55,082
  • 5
  • 77
  • 137