Overview
This article explains how to display commit numbers in Git Fork.
Why I wrote this post
At my company, I use Perforce for game development with Unreal Engine. Through that experience, I realized something convenient about Perforce compared to Git. Is it that submits are managed by numbers (changelist numbers).
Example: CL12345
When communicating with the team, we say things like, "That fix is reflected from CL12345 onward."
It’s easy to instantly see which submit is newer and how far changes have been applied. Also, larger numbers indicate newer commits, which makes searching convenient.
On the other hand, Git only uses SHA hashes for commits, making it tedious to check which commit is newer.
You can check with git show <commit SHA>
, but doing that every time is a hassle.
In Git Fork, commits are displayed like this:
Also, for packaged game versions, it seems the format Major.Minor.Patch.Changelist
is common (GPT told me so).
I thought it would be nice to insert the commit number into the Changelist part.
This time, I’ll explain how to show commit number in Git.
Environment
- Unreal Engine 5.6.0
- Git Fork 2.9.0.0
- Windows 11 Pro
Main Content
I use Git Fork, a GUI client for Git, so I’ll use Git Fork as an example.
Other clients like GitHub Desktop or Sourcetree should allow similar setups, so feel free to try.
By using git tag
, you can display custom information next to commits.
Normally, you can manually add tags by right-clicking a commit and selecting "Add Tag."
Additionally,
git rev-list --count HEAD
lets you get the current commit count.
If you automatically tag this number, the goal is achieved.
For example, you can confirm that there have been 4 commits:
We’ll now create a simple mechanism to automatically get this number and tag commits every time.
Using Git Hook
Git has a feature called "Hook" which are scripts that run automatically during specific Git events.
Edit the following file:
ProjectFolder/.git/hooks/post-commit
Add the following script:
project/.git/hooks/post-commit1# Get the total commit count 2count=$(git rev-list --count HEAD) 3 4# Create a tag like CL123 5tag_name="CL$count" 6 7# Create (or update) the tag 8git tag -f "$tag_name" 9 10# Optional: push it automatically if desired 11# git push origin "$tag_name" 12 13echo "Tagged commit as $tag_name"
If you want to share tags with the entire team, uncomment the line # git push origin "$tag_name"
by removing the #
.
That’s it!
Each time you commit, Git Fork will display the commit with CL<commit number>
next to it.
Result
If You Want to Bulk Delete Tags
Note that if you have thousands or tens of thousands of tags, Git performance may degrade.
In that case, I recommend bulk deleting unnecessary old tags and re-tagging from the latest commit.
Delete All Local Tags
1git tag | xargs -L 1 | xargs git tag --delete
Delete All Remote Tags
1git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete
Conclusion
Perforce really is convenient.
I can't help but wonder why, even while using Git, I still crave a Perforce-like experience...