user2138149
user2138149

Reputation: 17170

Git: How to figure out which version "master" aliases?

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

Upvotes: 1

Views: 190

Answers (1)

IMSoP
IMSoP

Reputation: 97898

"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

Upvotes: 1

Related Questions