Make it easy to learn how a given commit made it into master
My Git Blame Workflow
I often find myself using the following workflow:
-
Find what appears to be a bug
-
Decide to look for clues by finding the commit in which it was added
-
Visit the file on GitLab and click "blame" (or type
git blame ./path/to/some_file.js
in the shell) -
I find that the bug was introduced in a particular commit (let's say it's
2f87703c
) -
Try to figure out what MR contained
2f87703c
for some extra context.
I do this so often that I've put a handy script in my.gitconfig
aliases to locate the point at which a commit gets merged into a given branch:find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 | uniq -f1 -d | sort -n | tail -1 | cut -f2'" show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge'"
-
I type
git find-merge 2f87703c master
to get the SHA of the merge commit in whicha1b2c3d4
was added tomaster
(it returns46533a7d
). -
I then look up
46533a7d
and see that the commit message references MR!8095
. -
I look at all of the commits found in this MR to get the context I need to conclude my research.
Proposed Feature
I've found this find-merge
step so useful that I think it would warrant inclusion on GitLab itself. It would be amazing if I could just go to a commit page, and click a "get context" button to research where this commit ended up in master (i.e. which merge commit contains this commit).
Or include it right in the metadata next to where we show the branches:
Or even better yet, find the merge commit then cross reference that with any closed merge requests which reference this SHA and give a direct link to the merge request:
The latter two concepts may require too much processing to be done on every commit page load, so perhaps a "get context" button would be more practical for performance reasons.
This would be a very handy tool for anyone who does a lot of digging into commit history for context, and AFAIK our competitors have nothing like this.