threads / discuss / 62555

Understanding the diff output in gitk when comparing a commit with working tree

Subject: Understanding the diff output in gitk when comparing a commit with working tree

## tl;dr

2 messages between Nov 28, 2024 and Nov 29, 2024.

replies: 1people: 2as markdown or json

tobias.boesch@miele.com· Nov 28, 2024, 08:27 UTC · lore
Hello everyone,

in gitk one can compare commits by selecting one commit, then right click on another commit and use the different diff options in the context menu. That works great! I found that when comparing a commit with those changes made in the working tree, I don’t understand the following observations I made in the diff output for _some_ files:

- the diff output is not colored in red and green for additions and removals, but in red and bold black (still preceded with “++”, “+-“, “--“ and so on)
- some files show no differences, but an external diff shows that those differences are there
- the index of the diff shows an output like mentioned in the “combined diff” format (see https://git-scm.com/docs/diff-format#_combined_diff_format), and looks like “index NUMBER,NUMBER..NUMER”
Other files show up in a “normal” way; as a diff with red and green highlighted lines for additions and removals and no empty file diffs.
To reproduce this make some more changes in the working tree of a git repo. Then compare an older commit with the working tree in gitk and search for my observations in the diff output.
Can someone please explain me why all this happens?

Best wishes Tobias

------------------------------------------------------------------------------------------------- imperial-Werke oHG, Sitz Bünde, Registergericht Bad Oeynhausen - HRA 4825

Johannes Sixt· Nov 29, 2024, 07:38 UTC · re: tobias.boesch@miele.com · lore

Re: Understanding the diff output in gitk when comparing a commit with working tree

Am 28.11.24 um 09:27 schrieb tobias.boesch@miele.com:
Show 7 quoted lines
> I found that when comparing a commit with those changes made in the
> working tree, I don’t understand the following observations I made
> in the diff output for _some_ files:
> 
> - the diff output is not colored in red and green for additions and
> removals, but in red and bold black (still preceded with “++”, “+-“,
> “--“ and so on)

I will assume that there is no merge conflict. Then you see a combined diff where the "first parent" is the index and the "second parent" is the commit that you selected.

Without having looked at the code and its history, I guess that this is an accident that nobody has bothered to fix, because it is not a very useful way to show differences between the worktree and a selected commit.

-- Hannes

← back to recent threads