DEV Community

Discussion on: You should consider adding more detail to your commit messages

Collapse
 
mungojam profile image
Mark Adamson • Edited

I personally like commits to be fairly cheap to do. At the same time, I like people to generally use PRs to make changes as it is then clear exactly which commits made up a particular change. There's a balance and personal preference element as always.

Something that would really help me is if there was an easy way to find out what PR(s) a particular commit was part of. Then the blame could lead to the PR with the larger context. Any idea if that's possible in GitHub or other? I suppose if you have a git tool that shows you the commit in a tree then you could probably find the merge commit which then has the PR link in its name

Collapse
 
oliverjumpertz profile image
Oliver Jumpertz • Edited

If you're using GitHub, it's pretty easy to do.

With a context switch to the browser:
github.com/<username>/<projectname>/commit/<hash>
(as an example take this: github.com/expressjs/express/commi...)
If you go to the commit within the express js repository, you will notice that it says master (#3778) 4.17.1 4.17.0 in the header of that commit. #3778 is the Pull Request this commit found its way onto the master branch. :-)

If you want to stay in your local environment it gets a little trickier but is still doable!
I do not exactly know where I got this from but the disclaimer is, that I also found this somewhere, some time ago, so note that it's not my own.
This are two of the aliases I use (~/.gitconfig):

[alias]
    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 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
    show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge'"

git find-merge <commit-hash-you-want-to-track> will give you the hash of a merge commit, the commit you are searching for was part of, and git show-merge <commit-hash> will directly show all information about that merge commit.
Is this something that could help you?

Collapse
 
mungojam profile image
Mark Adamson

That's great, thanks for those tips, I shall try both next time

Thread Thread
 
oliverjumpertz profile image
Oliver Jumpertz • Edited

Great!
Just msg if there's something not working. :-)