I have an ugly history on my repo and I want to streamline-it a little bit. From what I've read, git rebase would be the tool I should use. What I want to do is:
Turn this:
A--------------------------I (master)
\ /
B--C-------------G--H--/ (development)
\ /
D--E--开发者_如何学C----/ (feature-1)
\ /
F--/ (feature-2)
Into this:
A-BCDEFH--I (master)
After the commit "I", I have other commits in the same form, so I would like my final history to look like:
A-BCDEFH--I--KLMNO-P (master)
Any pointers in how to accomplish this?
EDIT: Please note that in this example, D and F are not merge commits - they are standard commits, so none of them should dissapear from the history (although the merge commits, G and I should).
You can accomplish the first step with this:
$ git checkout -b new-master master
$ git rebase --onto A A new-master
Where A
is the commit identifier for the A commit in your graph.
This will create a new branch new-master
that will ultimately wind up in the shape you want master
in (merge commits that introduce no changes of their own will be dropped from the history). To port over the other branches, check them out one-by-one and issue git rebase --onto new-master master branchname
.
When you are satisfied with the changes, you can update the master
branch and delete new-master
:
$ git checkout master
$ git reset --hard new-master
$ git branch -d new-master
精彩评论