2

I noticed behavior of git I don't understand in this repository. It can be cloned via:

git clone "git@github.com:skript-sicherheit/skript.git"

If you navigate to the folder images in a terminal and execute git log ., it prints this:

commit b1703a7542ee226535a34bd3de9aed48a7f76a8d
Author: Lukas Beeck <meisterasrael@googelmail.com>
Date:   Wed Sep 7 10:37:39 2016 +0200

    Bild von Mona Lisa war verschwunden, ist wieder drin

commit 0e3ede155080a3005e6454d855e18dc0083ea01a
Author: Lukas Beeck <meisterasrael@googelmail.com>
Date:   Fri Sep 2 10:20:25 2016 +0200

    Erläuterung in Grafik eingefügt

[...]

git show b1703a7542ee226535a34bd3de9aed48a7f76a8d prints:

commit b1703a7542ee226535a34bd3de9aed48a7f76a8d
Author: Lukas Beeck <meisterasrael@googelmail.com>
Date:   Wed Sep 7 10:37:39 2016 +0200

    Bild von Mona Lisa war verschwunden, ist wieder drin

diff --git a/images/mona-lisa.jpg b/images/mona-lisa.jpg
new file mode 100644
index 0000000..f4f5583
Binary files /dev/null and b/images/mona-lisa.jpg differ

The commit message is German for: "Image of Mona Lisa had vanished. Is back in again."

So clearly, the file mona-lisa.jpg was changed by b1703a7542ee226535a34bd3de9aed48a7f76a8d. It even is the only file changed by it.

But if you execute git log mona-lisa.jpg, this is the (entire) output:

commit 669b00871f3dba5c43ac7d53e44f317a61b177d0
Merge: 921a31c 519cdae
Author: Lukas Beeck <meisterasrael@googelmail.com>
Date:   Fri Sep 2 15:39:00 2016 +0200

    Merge branch 'index'

Why doesn't b1703a7542ee226535a34bd3de9aed48a7f76a8d appear in the output of this command?

UTF-8
  • 575
  • 1
  • 5
  • 23

2 Answers2

0

I think you should pass the whole path of the file like git log images/mona-lisa.jpg

Rômulo Tone
  • 115
  • 6
0

More of a comment than a satisfactory answer, but it looks like something is strange about the sequence of events in that repository. From what I can, this is the situation:

master             | .. -> A -> B -> [E] (Mona Lisa) -> .. -> [H]
                   |                 /                        /
index              |     .. -> C -> D                        /  
                   |                                        /
seitenkanalgriffe  |                .. -> F (Mona Lisa) -> G 

It seems that for some reason, the Mona Lisa image is added in the merge commit E; I would guess maybe the untracked image was accidentally in the directory at the time and added by error.

The actual branch that it seems to have been intentionally committed in, is the seitenkanalgriffe branch, which is not merged until H.

The git log documentation when specifying a path states:

[--] <path>…​

Show only commits that are enough to explain how the files that match the specified paths came to be. See History Simplification below for details and other simplification modes.

Paths may need to be prefixed with ‘`-- '’ to separate them from options or the revision range, when confusion arises.

Since the important commit in terms of this file history is E, the commit which introduced the image, and H made no changes to the file, you will only see E when running git log mona-lisa.jpg. E is the commit with the "Merge branch 'index'" comment you mention in your question.

To further confuse things, if you use git log --follow images/mona-lisa.jpg, you will only see commit H, because it won't follow the file in merges by default. You'll have to run git log --follow -m images/mona-lisa.jpg to see commits E and H listed.

That is at least, my understanding of what is going on here, there may be something else to blame.

Chris
  • 8,268
  • 3
  • 33
  • 46
  • But why does it make a difference in terms of which commit is shown whether I ask git about the file's or the directory's history. Neither commit touches anything else in the directory. – UTF-8 Aug 15 '17 at 17:04
  • You seem to be right about how the image got first introduced. When hard-resetting to `669b0087`, the image is there. But when hard-resetting to its parents `921a31c9` and `519cdaed`, it isn't. All these commits are from the same person who appears to have intended to introduce the image in branch `seitenkanalangriffe` but accidentally introduced it while merging branch `index` into `master`, after which it was gone when he checked `seitenkanalangriffe` back out. He noticed that the image was gone (probably because the document didn't build) and added it again. – UTF-8 Aug 15 '17 at 19:49
  • How can one find out which commits touched a file? – UTF-8 Aug 15 '17 at 19:50
  • I would use `git log --follow` with flags as appropriate, but there are more thorough answers in https://stackoverflow.com/questions/3701404/list-all-commits-for-a-specific-file – Chris Aug 15 '17 at 22:01