1

I just downloaded OpenCV from git and with git branch I can see that currently I have master checked out. git checkout<tab><tab> indicates there are approx 100 different versions. For the project I am about to start working on I require at least version 4.1, however I suspect that "master" points to something like 3.4

Is there a way to check which version master is an alias for? It seems like a very simple thing to do I'm just not aware of how this is done.

Thanks

FreelanceConsultant
  • 9,832
  • 22
  • 88
  • 173
  • 2
    `git describe --tags --abbrev=0 --match=` https://git-scm.com/docs/git-describe – Marek R Apr 27 '21 at 11:44
  • https://stackoverflow.com/questions/14365946/git-branch-alias – Opri Apr 27 '21 at 11:48
  • @MarekR `git describe master` produces `4.5.4-57-....` - so I guess master is 4.5? – FreelanceConsultant Apr 27 '21 at 11:59
  • 3
    Are you working on a change to OpenCV or just using OpenCV for a project that is unrelated to OpenCV? If the latter, you don't need (or really even want) to be working with the git repo for OpenCV. `git` is not a distribution tool and really should not be used for installing software. – William Pursell Apr 27 '21 at 12:05
  • @FreelanceConsultant I've proposed something else! This thing you are seeing happens if invoke this command without `--abbrev=0` argument. – Marek R Apr 27 '21 at 12:50
  • @MarekR If you think you have an answer, post it in the Answer section, where you'll be able to edit as many times as you like, and people can vote and comment on it. This comment section is for clarifying the question. – IMSoP Apr 28 '21 at 09:02

1 Answers1

1

"master" is not an "alias" for any version number; or if it is, that is mostly coincidence.

"master" is a branch, which in git's model means "a movable pointer to a commit". Releases are generally marked with tags, which are a fixed pointer to a commit. It's possible that the movable pointer "master" currently points to the same commit as a fixed pointer like "3.4", but there is no requirement for it to do so.

Note that git itself has no idea what these pointers mean. The version numbers are something that the developers of the project have assigned. One common pattern is to have a single "master" branch which always has the latest changes, and occasionally assign a version number to some commit on that branch. But they might work on versions above 4 in a branch called "experimental", or versions below 5 in a branch called "legacy". They might also have "release branches" where final preparation for a stable release is done, so that the code on "master" is never exactly the same as any version released.

The best way to find that out is to read the documentation for the project, and follow its recommendations for where to find the best version of the code for your purposes. If you're not planning to make changes to the project, that will probably be to download a released version, and not use git at all.

If you are just curious, one way to see a list of commits and the branches and tags that point to them is using the "decoration" facilities of the git log command. For instance, I have an alias set up to run this command (*):

git log --oneline --graph --pretty=format:'%h %d %s'

This shows the history starting at whatever commit I have checked out, with one line per commit. The --graph adds an ASCII art diagram down the left showing how the commits relate in terms of merges, and the %d in the format string "decorates" each commit with any branches or tags pointing to it.

(*) actually, my alias runs git log --oneline --graph --pretty=format:'%Cred%h%Creset %C(yellow)%d%Creset %s' --color to make the different parts stand out more in different colours

IMSoP
  • 65,743
  • 7
  • 83
  • 127
  • Interesting: I thought the `%C(color)` syntax required the parentheses. Apparently it doesn't. Why is your `%C(yellow)` parenthesized when the rest are not? :-) – torek Apr 28 '21 at 00:58
  • @torek Hah! I've honestly no idea, this has been sitting in my gitconfig for years at this point, and I don't remember ever noticing the discrepancy. The parentheses seem logical, don't they. – IMSoP Apr 28 '21 at 08:59