2

Is it possible to add newlines or somehow format the output of git diff when called from the terminal?

Here is an excerpt from one of my git diff's, where after the previous file diff (ending at the last +), the next file diff starts.

+    def loader_collatefn(self, batch_list):
+        return data.dataloader.default_collate(batch_list)
+
+    def __getitem__(self, idx):
+        pass
+
+    def __len__(self):
+        pass
+
diff --git a/dataload/mrds_dataset.py b/dataload/mrds_dataset.py
index 9a5d60a..b751bc7 100644
--- a/dataload/mrds_dataset.py
+++ b/dataload/mrds_dataset.py
@@ -9,6 +9,7 @@ 
 from PIL import Image

 from . import DataPhase
+from . import BaseDataset

But, I think it would be more readable if there were a few newlines between each individual file's diff so that I can more easily see when the next file starts if I'm scrolling through the diff quickly.
Is there a git config option for this?

rasen58
  • 4,672
  • 8
  • 39
  • 74
  • 1
    that sounds more like something you would do by processing diff output, actually. That output format is pretty much standard *patch* format. – eftshift0 Jun 05 '19 at 23:26

1 Answers1

2

Try piping diff output into this:

git diff blah blah blah | sed 's/^diff/\n\n\ndiff/'

That will create the separation

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • 1
    That's good, but on some systems (like my Mac) it's tricky to get `sed` to recognize newlines. For example, on my machine your `\n\n\ndiff` pattern are printed like `nnndiff`. There are ways, but sometimes it's easier to just [give up on `sed`](https://stackoverflow.com/a/23790355/643383) and use `perl` instead: `git diff foo foo2 | perl -pe 's/(diff --git)/\n\n\n$1/'`. Awk is another good option. – Caleb Jun 06 '19 at 00:02