One day I’d like to add the Git commit hash to an “about” page in an app.
When that day comes, this post might be hepful.
tl;dr:
Add this to a new Run Script build phase:
GIT=`xcrun -find git`
GIT_REV=`${GIT} rev-parse --short HEAD`
/usr/libexec/PlistBuddy -c "Set :REVISION ${GIT_REV}" "${SRCROOT}/{{path-to-your-info.plist-file}}"
Then in the Swift code:
let revision = Bundle.main.object(forInfoDictionaryKey: "REVISION") as? String
Of course the key could be eg COMMIT_HASH
(or whatever) instead of REVISION
, if we wanted.