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?
-
I use Vim with fugitive and frequently use `Gblame` (`git blame` per line number) and `Gbrowse` (launch github in browser at current commit for highlighted lines). A combination of these features in Vim but contextual to the Pull Request would be THE BEST THING EVA. – Jacob Dalton Mar 14 '17 at 15:25
3 Answers
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.

- 143,130
- 81
- 406
- 459
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

- 3,905
- 27
- 46
I don't believe there is one at the moment.
However, you might wish to consider using meta data in commit messages e.g. referencing issues, features, stories etc. Pivotal Tracker has good support for these.
You could also include the pull request number in the commit that closes each pull request. See Closing issues via commit messages.
This article describes how you can use feature branches to keep track of pull requests in your commit history.
Finally, to add to @onionjake's answer, github has good support for git-notes too.

- 12,915
- 4
- 40
- 65