porthunt
porthunt

Reputation: 504

git rebase issue reordering

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

Upvotes: 1

Views: 112

Answers (1)

VonC
VonC

Reputation: 1323953

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

Upvotes: 1

Related Questions