2

I was exploring GitHub projects using git. Some things don't make sense to me.

For example in Opencv I can checkout to commit 539f065446a993825d61dddc5d9dc72ae54d7a29 (which is version 4.2.0). However when I use git rev-list --all to view the list of all commits, I don't find this hash (539f...).

Why is this the case? This is happening for many tagged commits.

Nelson G.
  • 5,145
  • 4
  • 43
  • 54
  • If you need the hash of the tagged commit, you can use the following code snippet from this [post](https://stackoverflow.com/questions/8796522/git-tag-list-display-commit-sha1-hashes): `git show-ref --tags -d` – flaxel Oct 18 '20 at 10:58
  • try following command: `git log --full-history`. look also git-docs [git-scm.com/docs/git-log](https://git-scm.com/docs/git-log) – SwissCodeMen Oct 18 '20 at 11:10
  • 4
    Are you sure that `539f...` is actually a *commit* hash, and not an annotated tag object? (`git cat-file -t 539f065446a993825d61dddc5d9dc72ae54d7a29` will tell you the object's type.) – torek Oct 18 '20 at 14:06
  • In my case the first commit I see with cmd: `git log --reverse --full-history -- $file` doesn't show my commit hash, but `git log --grep=pattern $file` - shows it so i'm also puzzled where my commit is getting lost in the `git log` history command ? ... – Ricky Levi Nov 13 '22 at 11:38

1 Answers1

1

As @torek points out, in this case 539f065446a993825d61dddc5d9dc72ae54d7a29 is not a commit hash but a ref to annotated tag object (vs lightweight tags) so it is not among commits refs. For this exact opencv project

$ cat .git/refs/tags/4.2.0
539f065446a993825d61dddc5d9dc72ae54d7a29

You can see the tagged commit ref and tag's ref as @flaxel points (the second is tag's related commit hash)

$ git show-ref --tags -d
...
539f065446a993825d61dddc5d9dc72ae54d7a29 refs/tags/4.2.0
bda89a6469aa79ecd8713967916bd754bff1d931 refs/tags/4.2.0^{}
...

$ git cat-file -t 539f065446a993825d61dddc5d9dc72ae54d7a29
tag

$ git cat-file -t bda89a6469aa79ecd8713967916bd754bff1d931
commit

$ git show-ref --head
0052d46b8e33c7bfe0e1450e4bff28b88f455570 HEAD
0052d46b8e33c7bfe0e1450e4bff28b88f455570 refs/heads/master
...
539f065446a993825d61dddc5d9dc72ae54d7a29 refs/tags/4.2.0
...

Annotated tag objects have extra meta data (tagger's name, email, date, message)

$ git show 539f065446a993825d61dddc5d9dc72ae54d7a29
tag 4.2.0
Tagger: Alexander Alekhin <alexander.alekhin@intel.com>
Date:   Fri Dec 20 16:44:16 2019 +0300

OpenCV 4.2.0

commit bda89a6469aa79ecd8713967916bd754bff1d931 (tag: 4.2.0)
Author: Alexander Alekhin <alexander.alekhin@intel.com>
Date:   Fri Dec 20 16:44:16 2019 +0300

    release: OpenCV 4.2.0
...

Annotated tag can be created with

git tag -a v1.0 -m "Adding tag 1.0 (tag's message)"
Vladislav Povorozniuc
  • 2,149
  • 25
  • 26