How can I rewrite the history of a published git branch in multiple steps?

Posted by Frerich Raabe on Stack Overflow See other posts from Stack Overflow or by Frerich Raabe
Published on 2010-04-19T12:07:48Z Indexed on 2010/04/19 12:13 UTC
Read the original article Hit count: 230

Filed under:
|
|

I've got a git repository with two branches, master and amazing_new_feature. The latter branch contains the work on, well, an amazing new feature. A colleague and me are both working on the same repository, and the two of us commit to both branches.

Now the work on the amazing new feature finished, and a bit more than 100 commits were accumulated in the amazing_new_feature branch. I'd like to clean those commits up a bit (using git rebase -i) before merging the work into master.

The issue we're facing is that it's quite a pain to rewrite/reorder all 100 commits in one go. Instead, what I'd like to do is:

  1. Rewrite/merge/reorder the first few commits in the amazing_new_feature branch and put the result into a dedicated branch which contains the 'cleaned up' history (say, a amazing_new_feature_ready_for_merge branch).
  2. Rebase the remaining amazing_new_feature branch on the amazing_new_feature_ready_for_merge branch.
  3. Repeat at 1.

My idea is that at some point, all the work from amazing_new_feature should be in amazing_new_feature_ready_for_merge and then I can merge the latter into master.

Is this a sensible approach, or are there better/easier/more fool-proff solutions to this problem? I'm especially scared about the second step of the above algorithm since it means rebasing a published branch. IIRC it's a dangerous thing to do.

© Stack Overflow or respective owner

Related posts about git

Related posts about history