1

When I run git log, I can see a commit that I created a few days ago, which contains changes to some file (let's call it x.txt).

However, when I run git log -p x.txt, which should show me the git changes on this file, I can't see the commit in question.

How could this situation be explained?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Yarin Gold
  • 489
  • 1
  • 4
  • 17
  • 1
    Does `git log -- x.txt` include the commit you think it should? – VonC Dec 22 '14 at 10:34
  • @VonC No it's not there :( – Yarin Gold Dec 22 '14 at 10:35
  • What happens if you take the commit SHA-1 that `git log` shows you (call that `XXXXXX`), and do a `git show XXXXXX`? Does it have the change in there? Perhaps the commit you think changed `x.txt` in fact did not change `x.txt`. Perhaps add that to the question, together with what `git diff XXXXXX{,^}` shows. – abligh Dec 22 '14 at 10:37
  • I already check it, and when I did git show `XXXXX`, I can see my change on `x.txt` – Yarin Gold Dec 22 '14 at 10:48

1 Answers1

2

git log -p uses actually a git diff option (--patch)

If git log -- x.txt doesn't show at all the expected commit, then it simply means that commit didn't introduced any diff for that file.
A git diff -- x.txt for that commit would be empty.

After extensive discussion, this work (which would mean x.txt was renamed or moved at some point):

git log --follow -M -p -- x.txt

There is another case where git log -p -- x.txt wouldn't include a commit:

That -p option will compare a commit with the previous one for a given file, unless that file was created (in which case, there is no previous commit for that file)

That means a git log -p -- x.txt won't include the first commit, when the file was initially added.
That "diff" would simply be the full content of x.txt.


In the OP Yarin Gold's case, though:

All that with a git version 1.9.3 (Apple Git-50) on OS X (10.9.5).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • My change (There is some change on the file) on the file was the second commit (the first one was of course the creation of the file). – Yarin Gold Dec 22 '14 at 10:49
  • @YarinGold if `git log -- x.txt` doesn't list your second commit, then that second commit didn't introduce any change to `x.txt`. I have rephrased my answer to make that clearer. – VonC Dec 22 '14 at 10:50
  • The second commit definitely have some change on the file. – Yarin Gold Dec 22 '14 at 10:52
  • Maybe some other developer did something that caused it? that's what I'm trying to figure out. – Yarin Gold Dec 22 '14 at 10:53
  • @YarinGold but you said `git log -- x.txt` didn't include that commit? It does mean this commit definitively did *not* introduced any change to `x.txt`, does it not? – VonC Dec 22 '14 at 10:57
  • I see your point but it does not the case for me. I have change on `x.txt` file but it does not show it on `git log -- x.txt` – Yarin Gold Dec 22 '14 at 11:00
  • @YarinGold does `git show -- x.txt` returns any diff? – VonC Dec 22 '14 at 11:01
  • @YarinGold and are we talking about the same `x.txt`? (maybe there is a case issue? a `X.txt`?) – VonC Dec 22 '14 at 11:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67457/discussion-between-yarin-gold-and-vonc). – Yarin Gold Dec 22 '14 at 11:02
  • @YarinGold regarding the rename, as in http://stackoverflow.com/a/13620202/6309, what a `git log --format='%H%%' --name-only --follow -- x.txt | sed ':a;N;$!ba;s/%\n\n/ /g'` returns? – VonC Dec 22 '14 at 16:57
  • it returns `d0f768003b9423b42a63426f3d51f3bcd6ec217e% app/serializers/api/v1/cms/listed_product_serializer.rb 21e85b33c6be5fffa4bf46800b8af1333d7e4876% app/serializers/api/v1/cms/listed_product_serializer.rb af8e86070fd9030679781a18ce50a6fe088cc70c% app/serializers/api/v1/cms/listed_product_serializer.rb` The `listed_product_serializer.rb` is the `x.txt` in that case. – Yarin Gold Dec 23 '14 at 08:25
  • @YarinGold strange... not much rename/move there to see. Is that *all* the commits for that file? Would adding `--all` to the `git log` command generates more commits? (or `--all --branches`) – VonC Dec 23 '14 at 10:52
  • It's still returns the same results with `--all` or `--all --branches`, it looks like it wasn't renamed, so I still don't understand why `--follow` gives me the missing data. – Yarin Gold Dec 23 '14 at 12:10
  • @YarinGold indeed... that should be the topic of a separate question (with a link back to this one) in order to focus on that peculiar behavior. – VonC Dec 23 '14 at 13:21