1

I am trying to do an interactive rebase to change an email of a pull request. It appears in the git log

commit 0b7e8dc4ebe9fb6ee4394cbf6effb3d43b8cd6a8
Merge: 9de954e 30a5ede
Author: test user <testuser@gmail.com>
Date:   Sun Feb 11 08:29:41 2018 +0100

    Merge pull request #1 from tester/greenkeep/initial

So I know it's there, but when I try and do a rebase, I do not see it.

I see every other commit. Is there some special case?

The pull request was on a github.

I know it's not recommended to rewrite history, I have done this before BUT with the pull request, it seems to be missing?

The thing that is really confusing is that the git rebase -i doesn't even show the pull request message. I even tried

git rebase -i head~20

which I know the pull request lands in as it was done a couple of commits back.

Any ideas?

halfer
  • 19,824
  • 17
  • 99
  • 186
Martin
  • 23,844
  • 55
  • 201
  • 327

1 Answers1

3

Rebase discards merges by default, as in the linked question.

A pull request is, in essence, sending a message to someone else asking them to merge or rebase your commit(s) into their work, so the first question to answer is whether you need your own merge in this series of commits. If they choose to rebase your series of commits, their rebase will discard your merge anyway. (This is also true if they choose the non-merge "squash" option on GitHub. You can make pull requests the old-school way without GitHub, but since you have tagged this with I will assume that you made the pull request using GitHub too.)

If they are going to merge, though, then your merge will be included in the series of commits they add to their repository when they merge your commits. In that case, you might want to replace your existing merge commit (with its incorrect author) with a new corrected merge commit (with correct author). That could be fairly hard, if it's not right at the tip of your series of commits. In that case, do see the answers to Rebasing a Git merge commit, and note that git rebase --preserve-merges actually re-performs the merge.

You might also consider using git filter-branch to change just one commit, as in Change the author and committer name and e-mail of multiple commits in Git but using the $GIT_COMMIT variable to test for the one specific commit hash ID. Note that filter-branch is tricky to use correctly; always experiment on a copy of the repository.

If the merge commit is right at the tip of the commits you're asking someone else to pull, though, there is a much easier way to do this: just use git commit --amend --reset-author. The --amend code knows how to copy a merge commit to an amended merge commit, and since there are no commits after the merge commit, there are no subsequent commits that require a copy-with-something-changed operation to use the new "amended" commit's new hash ID.

(The filter-branch and interactive-rebase code are complicated in part because once you've copied-but-adjusted a commit in the middle of a series of commits, every subsequent commit must also be copied-but-adjusted, to use the new hash ID of their replacement parent. When using git commit --amend, there are no subsequent commits, so this complication simply vanishes.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thanks. yes, thats what i needed. – Martin Feb 15 '18 at 07:56
  • 1
    TL;DR `git commit --amend --reset-author` – Rakib Sep 08 '22 at 11:22
  • @Rakib: that only works when the commit you want to swap out (for a new and improved commit) is the *last* commit in the chain. I personally find this to be uncommon, but others have different workflows. – torek Sep 08 '22 at 16:15