3

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.

kagarlickij
  • 7,327
  • 10
  • 36
  • 71

1 Answers1

2

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.

Gary Ewan Park
  • 17,610
  • 5
  • 42
  • 60
  • hello and thanks for help, ignoring all commits before certain date seems to be the most convenient in my case, this is test project's output without any ignoring - http://prntscr.com/giky4t , here's GitVersion.yml file - http://prntscr.com/gikyku ; and here's output with GitVersion file - http://prntscr.com/gikz12 – kagarlickij Sep 08 '17 at 09:28
  • Does that selected date effectively exclude ALL history of the repository? If so, you may need to make at least 1 commit into the repo, that is in a valid date range, in order for GitVersion to work. – Gary Ewan Park Sep 08 '17 at 09:57
  • Hmmm, honestly not sure then. Is this a public repo, i.e. can I have a look? What version of GitVersion are you using? – Gary Ewan Park Sep 08 '17 at 11:20
  • Gary, sorry, I was on the sick leave, but now I can provide all required info to you, repo - https://github.com/kagarlickij/fa , Gitversion version is 3.6.4.0 - http://prntscr.com/gm8s9b – kagarlickij Sep 17 '17 at 15:42
  • So, that repository that you point at doesn't have a GitVersion Configuration file, and as of right now, it is asserting a version number of 5.0.0. I am assuming that this isn't what you want. What is it that you would like it to be? – Gary Ewan Park Sep 17 '17 at 16:15
  • Gary, thanks for keeping this up, I want to decrement version by ignoring all commits before certain date, here's my GitVersion.yml - https://gist.github.com/kagarlickij/552faebcd77c77e7a73e440cc093902d . But issue still looks like this - http://prntscr.com/gm9f0s – kagarlickij Sep 17 '17 at 16:36
  • I have done a couple of tests, and the ignore sections in the GitVersion.yml file only seem to ignore commits, they don't take into account the tags on a repository. The only way to begin the counting again, from an earlier version number, would be to remove the tags that have been applied to the repository. Is that an option? – Gary Ewan Park Sep 17 '17 at 16:59
  • Gary, this is acceptable option, I've removed tag but gitversion is the same 5.0.0 - http://prntscr.com/gm9vx7 . After that I've added the same GitVersion.yml and it produces the same error - http://prntscr.com/gm9wka – kagarlickij Sep 17 '17 at 17:17
  • Did you remove the gitversion_cache that I mentioned in my answer above? I had to remove this, otherwise the cached version number was still being returned, rather than the new one based on the lack of tag. – Gary Ewan Park Sep 17 '17 at 18:42
  • Sorry, not sure what to say... For me, removing the tag from the repo, clearing the cache, and running gitversion again, resulted in a version starting with 0.1.0. – Gary Ewan Park Sep 18 '17 at 21:25
  • Just to be clear... Based on the sample repository that you linked to, and the removal of the tag, I no longer had the need to use a GitVersion.yml file. Can you confirm that you are also no longer using one? – Gary Ewan Park Sep 19 '17 at 07:32
  • Sure, I don't use GitVersion.yml – kagarlickij Sep 20 '17 at 15:48
  • Hmmm, in which case, I can't explain why you are seeing a different result. Sorry :-( – Gary Ewan Park Sep 20 '17 at 17:26
  • 1
    I'm going to create one more test project this week to test the whole story one more time – kagarlickij Sep 20 '17 at 19:16