Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS - Automatic Version Numbering
# Use last tag as the base for the version. E.g. tag initial commit as 0.0
LAST_TAG_VERSION=`git describe --tags | cut -f1 -d"-"`
# Optional. Same as above but keeps the commit hash
#LAST_TAG_VERSION=`git describe --tags`
# Total number of commits in the repository
TOTAL_COMMITS=`git rev-list HEAD --count`
# Write the version numbers to the compiled product
defaults write "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}" "CFBundleShortVersionString" "${LAST_TAG_VERSION#*v}.${TOTAL_COMMITS}"
defaults write "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH%.*}" "CFBundleVersion" "${LAST_TAG_VERSION#*v}.${TOTAL_COMMITS}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment