2

I use number of commits as version of my program (Using hash of commit as version very inconvenient, becouse it not sequential). So I obtain commit number:

git rev-list --count HEAD

For example for current state it outputs 53. Can I do checkout to commit number 35? Or obtain hash of commit number 35?

knittl
  • 246,190
  • 53
  • 318
  • 364
Ivan Borshchov
  • 3,036
  • 5
  • 40
  • 62
  • 3
    This sounds like a really bad idea. This will certainly cause issues when you're using multiple branches or when you have multiple people working on the same code base, including local branches, local commits, etc. I suggest you start using something like a manually assigned version number. If you want, you can still add a build number or version hash, or time stamp to differentiate between builds. – nwinkler Feb 23 '15 at 10:37
  • I'd suggest to use incremental builds via CI server (Jenkins or any other). In this case you don't need to do versions manually - just configure the build after every commit. New app build will have new version automatically. – Vitalliuss Feb 23 '15 at 11:05
  • 4
    You can checkout for `HEAD~18`. Where `18 = 53 - 35`. However that won't work with branches as @nwinkler mentioned. It will only use the first parent, ignoring the second. – Sbls Feb 23 '15 at 11:14

1 Answers1

-1

I don't recommend using number of commits as a version. If you use rebase to modify commits then it will create problem in the future. I suggest you to use git tag <tag_name> create new tag and use it as a version. See more here

rafathasan
  • 524
  • 3
  • 15
  • Yes, during last 7 years I understood it is not universal approach, commit probably could be used as version identifier, but true version should follow SemVer and should be defined manually, or semi-automatically by autoincrementing patch and manual bump for minor major versions when backward compatibility affected. Though all depend on all, what kind of artifact you are releasing, if it is package the rules will be quite different when you are building for example an Android app – Ivan Borshchov Oct 21 '22 at 09:44