I’ve made this little helper script which automatically saves the git hash into a text asset before build and (optionally) warns you if you still have uncommitted changes. I know there are some solutions out there but I just wanted a very lightweight one. Most of the code is actually for settings.
It’s just one single file and free (MIT license) on GitHub (more info there) or just use the file which is attached to this thread:
I use it to display the hash at runtime and also remind myself to commit changes before builds.
Requirements
- You need to have git installed (“git” command in PATH). To test simply open your commandline, type in “git” and see what happens.
- Your project must use git (obviously).
- Unity 2017+ (may work with earlier versions too, have not tested it there) up to 2020+
Usage
At build time it will try to fetch the current hash from git and save it in a text asset (default: “Assets/Resources/GitHash.asset”).
This is how the warning looks:
Update: Fix applied thanks to “EVC_Keys”.
More details and readme on GitHub.
Cheers!
6783542–804230–EditorGitTool.cs (10.3 KB)