Decrement GitVersion SemVer

1.5k views Asked by At

My current GitVersion in 3.2.1, but it was done by mistake a while ago.

How can I decrement version to 2.2.1?

I'm using TeamCity if it's important.

1

There are 1 answers

14
Gary Ewan Park On

This is an interesting question...

What it comes down to is, how the version is/was being asserted. For example, what exactly do you mean by done by mistake?

If you mean that you incorrectly tagged the repository with 3.2.1, and you have now removed that tag, then it might be as simple as removing the the cache of asserted version numbers that GitVersion creates. This can be found in the .git\gitversion_cache folder within your repository. Either remove a single file representing the SHA of the commit you are running against, or delete the entire folder. Due to the time it can take GitVersion to assert the version number, having a cache of asserted version numbers is really useful. However, if something changes from a configuration point of view, GitVersion can get confused and return the wrong version number.

If the 3.2.1 version number is being established due to a version bump in a commit message, then it is possible to have GitVersion ignore specific commits in the git history. You can see an example of this in action here in the GitVersion.yml file:

https://github.com/cake-build/cake/blob/develop/GitVersion.yml#L15

Example

ignore:
  sha:
    - 2a4757b270f7946122ba6622e3d2e72b2b2808a7
    - 3e91c23637b97bc4e4c3234f93ffd03e6af70e8c

This was necessary due to the commit message of these commits:

https://github.com/cake-build/cake/commit/2a4757b270f7946122ba6622e3d2e72b2b2808a7 https://github.com/cake-build/cake/commit/3e91c23637b97bc4e4c3234f93ffd03e6af70e8c

where the version number in the commit messages was causing GitVersion to incorrectly bump the asserted version number.

If you essentially want to do a reset, and starting GitVersion numbering again, you could use another technique of ignoring all commit messages prior to a certain date. This is documented here:

http://gitversion.readthedocs.io/en/latest/configuration/#commits-before

Example

ignore:
  commits-before: 2017-09-08T08:08:00

Therefore, the asserted version number would only be calculated as a result of commits after the date specified above.