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?

1
  • 1
    that sounds more like something you would do by processing diff output, actually. That output format is pretty much standard patch format.
    – eftshift0
    Commented Jun 5, 2019 at 23:26

1 Answer 1

2

Try piping diff output into this:

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

That will create the separation

1
  • 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 and use perl instead: git diff foo foo2 | perl -pe 's/(diff --git)/\n\n\n$1/'. Awk is another good option.
    – Caleb
    Commented Jun 6, 2019 at 0:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.