< Back

# Git Commit-Hash based Build Versioning for your iOS Project

When it comes to distributing your Build to your Customer(s) or other devs, you need (and you really should also want) to bear in mind which version is running on their devices.

Aand I mean which seperate Git Commit as I think semantic Versioning for Alpha/Beta Testing is not neccessary as the Apps undergoes dramatic changes pretty fast, correct me if I’m wrong.

Edit: As Apple requires you to use a decimal-only Build Version, we need to recalculate the hex hash as an integer. As I’ve expected an issue with calculating a hexadecimal longer than FF using plain bash, I’ve decided to use Python.

One single line of code can make you life much easier as it replaces (on Release Scheme Build only) your App’s Info.plist’s CFBundleVersion with the current (short) Git Commit:

if [ $CONFIGURATION == Release ]; then
	REVISION=$(python -c "print(int('$(git log --pretty=format:'%h' -n 1)', 16))")
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion ${REVISION}" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi

Just create another Build Phase in your App’s Project, move it to the top add this one line. Voilá!

Impressum • Mastodon