0

I have looked at many explanations about what git diff between 2 commits does, and I am still completely baffled about the output I am getting. I believe what I am seeing is "combined format", said to be the "default" format, but if so I don't know what other formats are available.

Example:

>git diff af738ab0..bbbec26d > gitdiff_2025-04-09B.diff

Typically I get this kind of thing:

...
+diff --git a/src/core/history_table_view.py b/src/core/history_table_view.py
+index 5b18236..05b262a 100644
+--- a/src/core/history_table_view.py
++++ b/src/core/history_table_view.py
+@@ -14,188 +14,279 @@ class HistoryTableView(QtWidgets.QTableView):
+     @thread_check(True)
+     def __init__(self, *args):
+         super().__init__(*args)
+-        self.setObjectName('history table')
+-        self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
+-        self.horizontalHeader().setStretchLastSection(True)
+-        self.horizontalHeader().hide()
+-        self.verticalHeader().hide()
+-        self.setModel(HistoryTableModel(self))
...

... in this part of the output it is comparing the file history_table_view.py in the first commit with the same file in the second commit.

All the above lines are present in both files. So why might this line

+     def __init__(self, *args):    

start with a simple "+", whereas this line

+-        self.setObjectName('history table')

starts with "+-"? What does this mean? As I say both lines are present in both versions of this file. I would expect a git diff in principle not to show any of these lines (although there are some differences in terms of empty lines between the lines with text).

Secondly, when I look at a simple intro to git diff, such as this, the presenter there does a git diff on 2 commits, at 4:40 into that video we see output ... but in his case he is NOT seeing double symbols at the start of lines, but simple "+" or "-", i.e. as far as I understand it what one might expect from a BASH diff command done between two files. THAT SIMPLE FORMAT IS ALL I WANT.

I suspect that there may be an alternative to git diff "combined format" which does indeed produce this simpler output, but I haven't been able to find it. Secondly, the video I reference above was made 7 months ago: why is that Youtuber getting by default, when comparing 2 commits, simple git output (which is perfectly comprehensible to me), while I'm getting (to me) incomprehensible output? My git version is:

git version 2.48.1.windows.1

A simple link to a page which genuinely explains this specific business of git diff comparing 2 commits, in clear terms, and crucially showing how to get a simple diff, might be all I need. I have searched long and hard and not found.

Later.
Can the daoh-nvohter please say why this question is not worthy of being asked?

8
  • Assuming that is a normal file (and not a patch), then it is showing up output that you see on merge-commits. Each +/- sign shows how that line is seen from each parent of the merge commit. Now, why do you see that in plain diff, I don't know. Commented Apr 10 at 7:19
  • Of course, another simple explanation would be that src/core/history_table_view.py has those lines starting with - in commit bbbec26d.... is that the case? Commented Apr 10 at 7:21
  • 5
    I very much suspect that you accidentally committed (added) a patch file, and you are showing us only part of that diff. I.e., you first did git diff a b > file.diff, and later you did git add .; git commit, and now you are showing us the result of git diff a c, where c is the commit you just made. Commented Apr 10 at 7:32
  • 3
    +diff --git a/src/core/his... the line mentioning that file also starts with a +. Go higher into your diff (to the nearest line which starts with diff ... without a leading + or -) to get the name of the culprit patch file. Commented Apr 10 at 7:35
  • 1
    also, to spot the patch file(s): git grep -l -e "^diff --git" bbbec26d Commented Apr 10 at 8:22

1 Answer 1

2

There is a patch file in your second commit, your a reading a section of the diff which describes "that patch file is added".


If you want to spot such patch file(s) in a commit, you can for example look for the pattern ^diff --git in the files of said commit:

git grep -l -e "^diff --git" <commit sha>

run it for example on your bbbec26d commit: git grep -l -e "^diff --git" bbbec26d

If you see lines with leading -- or -+, this means you also have patch file(s) in your first commit af738ab0

If you want to have git diff only on a set of files, use the glob syntax for [path...]:

git diff af738ab0..bbbec26d -- src/ test/   # only files under src/ and test/
git diff af738ab0..bbbec26d -- '*.py'       # only files with that suffix
# or
git diff af738ab0..bbbec26d -- ':!deploy/'  # not that directory
git diff af738ab0..bbbec26d -- ':!*.patch'  # not files ending with that suffix
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.