问题
My team is using github to manage a private repo full of cms themes. We have them all within the same repo and keep track of them with subfolders, labels and keeping our branchs and commits prefixed with the theme name
IE
Commit message: "[Super Theme] upgraded Navigation to include hover effect"
Branch super_theme-upgrade-navigation-hover
Now we want to introduce semantic versioning into the theme's settings page so if you click about, you get the version number, but I'm not sure the best way to implement this
We could use git tags and git describe to check the number of commits but this only works if each folder is its own repo. We want to keep them together because it makes discussions on github easier since an issue affecting one theme often affects another. They're all different, but very closely related.
I thought about adding a script for us to check the current version of in the theme's json file and incrementing it, but I'm not sure if this is automatic enough. I really want to be sure that we don't run into version conflicts with everyone on the team. Not sure if submodules would work here since we want them always up to date.
I want a way to update the version number for a subfolder only when a branch working on that folder is merged into master.
Stumped. I'm not even sure if thats a clear question, so please ask for clarification.
回答1:
Here's one approach to attaching a subfolder version to the git history:
git describe $(git log -n 1 --format=%H -- path/to/subfolder)
This allows using a top-level tag to track major/minor versioning (e.g. tag named 1.0), with revision tracking the commit/hash specific to the subfolder (e.g. 1.0-25-gcdcb9a7e). Depending on whether you're publishing build artifacts (e.g. Maven, PyPI) you might need to tweak to match constraints on version naming, or dump the hash to some artifact metadata. Including the hash somewhere in the artifact can be super useful for traceability.
回答2:
It is actually possible to tag objects other than commits. You could therefore tag the tree of your sub-folder like this (the -a
is optional):
git tag path/to/subfolder/v-1.2.4 HEAD:path/to/subfolder -a
To find out the version for the sub-folder in a particular commit use the following:
git for-each-ref refs/tags/path/to/subfolder/ --format='%(object) %(refname:short)' | grep $(git rev-parse <commit>:path/to/subfolder) | cut -c 41-
However, unlike git describe, this will not give you the most recent version unless there is an exact match.
来源:https://stackoverflow.com/questions/29418611/tracking-version-numbers-of-subfolders-in-git