1

I'm having an issue while rebasing git commits. The problem is:

pick A
pick B <- mine
pick C 
pick D
pick E <- mine
pick F <- mine

I want to squash all my commits into one. I planned to do something like:

pick A
pick C 
pick D
pick B <- mine
squash E <- mine
squash F <- mine

But that didn't work because if I execute this git rebase, the commmit A, C and D would be mine as well. If I just delete the lines from A to D, leaving just:

pick B <- mine
squash E <- mine
squash F <- mine

the commits A, C and D will be deleted. How can I handle this?

Thanks

porthunt
  • 484
  • 1
  • 5
  • 12
  • 2
    “because if I execute this git rebase, the commmit A, C and D would be mine as well” No, that shouldn’t be the case. You'll be their committer, but not author. – Ry- Mar 14 '17 at 05:07
  • But I think for a PR on a OS project it would be a little weird to be committer on something you didn't work on, right? – porthunt Mar 14 '17 at 05:11
  • Not really. Committer isn’t particularly important information, and if you’re rewriting commits, there’s not much point pretending you didn’t. In this particular case, you can rebase off `A` instead and save one change (because you’re not changing it), though. – Ry- Mar 14 '17 at 05:13
  • Another issue that I've seen is: In github I see that the last 3 commits are mine (B, E, F). Also it is the same for git log. But when I use `git rebase -i HEAD~3`, my commits are not in the same order as `git log`. – porthunt Mar 14 '17 at 05:15
  • rebase displays commits from oldest to newest. The log is the opposite. – Ry- Mar 14 '17 at 05:30

1 Answers1

1

As mentioned in How can I rebase a commit made by another author without adding myself as the committer?, you could try and change the GIT_COMMITTER_NAME/EMAIL variables, but that would apply to all commits rebased.

Another approach is to perform your rebase, then complete it with a git filter-branch to change only A, C and D.

git filter-branch --commit-filter \
  'export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; \
   export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; \
   export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; \
   git commit-tree "$@"' -- D..HEAD
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250