7

I'm new to GIT, but i can't find out how to :

  1. Get the version of a repository (folder offline)
  2. Get the last version of a repository (online)

I can only compare the two, but it doesn't give me any information about the version. : git status, just tell me it's up to date.

How can i have something like this :

Your version : 1.9.0
Latest version : 1.10.1

With conky as example : https://github.com/brndnmtthws/conky

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
bob dylan
  • 989
  • 2
  • 10
  • 26

4 Answers4

9

There's really no clean way to do this, since "current" version of the repository means different things to different people. It also strongly depends on whether or not tags are used.

In this scenario, if you want to rely exclusively on the tags, then you can use git tag -l to get a listing of all tags, with the most recent one created being the last entry.

If you want the most recently committed work, you'd have to look at the branches of your own volition and inspect when something was committed. In this case, it's master, so all you'd need to do is perform a log on it.

git checkout master && git log
Makoto
  • 104,088
  • 27
  • 192
  • 230
4

Git repositories don't have any kind of a monolithic "version", that they can be labeled with.

A git repository has one or more branches, with some commit at the head of each branch.

Git repositories also have a few other ancillary details, like tags.

Git is not like subversion, or CVS. There is no monolithic "version" identifier that gets incremented with every commit. Git doesn't work like that.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • Also, `git branch -vv` shows you if you are ahead or behind a remote branch. – pfnuesel Feb 29 '16 at 03:25
  • If i'm only interested in the default master branch : https://github.com/brndnmtthws/conky/releases on this link you can see just under the "Latest release" green button is a TAG icon with a text inside (v1.10.1 in this case) If this TAG exist, is there really no way to request that with a git command ? – bob dylan Feb 29 '16 at 03:30
  • @bobdylan - If you are interested only in the master branch: "git log --format=short master^..master" displays the commit at the head of the master branch. The long hexadecimal string next to "commit" specifies the head commit, which would be the concept that's closest to the "version" of the branch. – Sam Varshavchik Feb 29 '16 at 03:36
3

This describes your version of master:

git describe --abbrev=7 --always  --long --match v* master

This describes the master on the remote repo:

git describe --abbrev=7 --always  --long --match v* origin/master

The version will look like this:

v1.11.5-25-gb2a5a47
Simon Byholm
  • 390
  • 3
  • 10
0

You can always execute a git fetch command (which will cover both of your questions)

git fetch --all --prune

This command will update your local repository with all the latest code from the remote repository.

Once you do it you can merge code into your branch from the local repo (offline)

CodeWizard
  • 128,036
  • 21
  • 144
  • 167