Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git equivalent of svnversion [duplicate]

Possible Duplicate:
what is the git equivalent for revision number?

I have been using subversion for same time now, and would like to switch to git. Having read the manual I have only one reservation, I use svnversion to get a reference number that is: unique, short, monotonic with respect to time (always increases).

  • It must be unique, so I can use it to reproduce the article.
  • It must be short, so it is readable, can be used in file-names, page footers, version number displays.
  • It must only increase ( monotonic with respect to time ), so any one can compare the age of two articles, without knowing the age (date).

Constraint: If we can get a branch ID than the above requirements only have to be met for articles on the same branch. (Branch ID can be anything that can be compared for identity, “is this the release branch?”.

[The word article is used here to represent a computer program, document or something else that is generated from the content of the revision control system.]

like image 305
ctrl-alt-delor Avatar asked Sep 18 '12 10:09

ctrl-alt-delor


People also ask

Is Git faster than SVN?

Git has the advantage that it's MUCH better suited if some developers are not always connected to the master repository. Also, it's much faster than SVN. And from what I hear, branching and merging support is a lot better (which is to be expected, as these are the core reasons it was written).

What is Subversion in Git?

What is Git-SVN? The git-svn tool is an interface between a local Git repository and a remote SVN repository. Git-svn lets developers write code and create commits locally with Git, then push them up to a central SVN repository with svn commit-style behavior.

What is better SVN or Git?

SVN is better than Git for architecture performance, binary files, and usability. And it may be better for access control and auditability, based on your needs.

Is Git similar to SVN?

The Git workflow is similar to SVN, but with an extra step: to create a new feature, you take an exact copy of the central repository to create your local repository on your local machine (you can think of this as your “local trunk”).


3 Answers

As fork0 stated there's no such equivalent for non-linear histories, you can anyway execute this to get the number of commits for the current branch:

git log --oneline | wc -l

This is what one of my team mates use for generating a build number to be used in the build scripts.

like image 108
rgngl Avatar answered Sep 30 '22 16:09

rgngl


No, there is no such thing for non-linear history. But you might look at git describe, its output will meet at least the two first criteria.

like image 45
fork0 Avatar answered Oct 04 '22 16:10

fork0


The point of the build number is to simplify a process to get a source code for a given build. You could use git show -s --pretty=format:%h to get a sha1 number which uniquely identifies a version, so that any developer could checkout it in his repository.

However, the sha1 is not incremental number and it is impossible to have in most cases even with other VCSs. If you wish to have it, then it is better to introduce a Continuous Integration system (e.g. Jenkins) which will number builds incrementally and create tags for these numbers. In this case it will grow more moderately, because CI usually doesn't build each commit.

Also, the mentioned git describe does a great job to generate good version names.

like image 26
kan Avatar answered Oct 03 '22 16:10

kan