In a reasonable "merge-only to master" git workflow (e.g. gitflow) - all changes happen in branches, which in turn get merged (perhaps as part of a Pull Request) - how do I handle versioning?
For tagging, I easily can git tag
the particular merge commit, no big deal.
But many app frameworks rely on a version file (e.g. package.json
or gemspec
or even custom files).
I see a few options:
- Modify the file as part of the branch. This isn't great, since you rarely know in advance which version will get merged in first, especially with a large team with many branches running in parallel.
- Modify the file after commit. This isn't great, since a- I now commit to master, and b- automated CI/CD will grab the previous commit and release it, but it has the old version number and c- with 2 commits to master for one release, it is possible to check out the wrong version; easy human error.
- Make the version file a template and auto-generate it from the git tag. This, too, isn't great, since local tooling will break on it (try running
npm <anything>
with an invalidpackage.json
), and the repo no longer can stand on its own as an atomic unit.
Is there a reasonably standard way to do this when versioning is in a file that is part of the commit?