1

My Github repository has received a pull request consisting of several commits. I only want to accept the first of these. Is there any way I can do this without asking the PR author to change their PR?

The PR was sent a long time ago and I've been unable to reach the author. I realise that I could just create a new commit myself, but I'd prefer to have the original commit author's name on the commit.

Anna
  • 2,645
  • 5
  • 25
  • 34
  • Make a new branch from the first commit, and merge it. – matt Feb 18 '22 at 11:58
  • @matt How can I do that? I looked at [this answer](https://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git) but couldn't see how to handle that the commit is in a pull request. – Anna Feb 18 '22 at 12:10
  • Why does the pull request make a difference? A commit is a commit. – matt Feb 18 '22 at 12:13
  • You cannot do this with the GitHub interface. It's easy to do with command-line Git though; see [phd's answer](https://stackoverflow.com/a/71173667/1256452). – torek Feb 19 '22 at 09:14

1 Answers1

2

I'd prefer to have the original commit author's name on the commit.

Nice and polite!

The first approach: create a commit and artificially assign it to a different author using git commit --author=<author>. You can even change author's date to the date of the commit at GH: --date=<date>.

The second approach is: fetch the PR from GH to a local branch and merge/cherry-pick one commit from the branch:

git fetch origin pull/$ID/head:pr-$ID # fetch the PR into branch pr-$ID
git log pr-$ID # view commits and find the one
git merge $COMMIT_ID

PS. Next time please use search.

phd
  • 82,685
  • 13
  • 120
  • 165