I'd like something like "git blame" for pull requests. In order to audit changes on a file, I need to annotate a file with references to the pull request (rather than the commit) that merged each change (supposing there is one). Is there a tool to do this?
If there's a specific line you're interested in, you can use an ordinary commit-based blame to get the SHA of the commit that last touched that line and then use GitHub's ability to search by SHA to find the pull request that introduced that commit. (Or, strictly, all pull requests containing that commit, of which there might be many or none.)
So, to take an arbitrary example, if I want to PR-blame line 4 of https://github.com/kennethreitz/requests/blob/master/setup.py, first I click the blame button:
Then I note the SHA of the commit for the line I'm interested in, and enter it into the repository search bar at the top of the page:
Then I search, select "Issues", and the relevant PR appears:
It would be impractical (or tedious, at best) to do this for every line of a file, like the OP here wanted, but hopefully this approach will at least be helpful to people interested in PR-blaming a specific line.
git-notes might be what you need.
First you would add a note to each commit with its pull request (e.g. git notes add -m 'Pull-Request: 5' <sha1>
).
Then you can use git-blame to lookup those pull request notes for each line in the file. Here might be an example:
$ git blame --line-porcelain <some file> | grep -P '^(\w|\d){40}' |
ruby -ne 'print $_.strip + " " ; puts `git notes show #{$_.split[0]}`'
67a262e6951b17ba0bc7adfcf1c7e5e1596efafd 1 1 1 Pull-Request: 2
0fd6a5000552f0d916079a7a965087acf2d3ad26 2 2 1 Pull-Request: 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With