Rewrite / edit a commit earlier in history
I'm looking for the recommended strategy to rewrite a commit (in my case split it in two, but there could be other cases) earlier in history. That is basically what can be achieved in git with git rebase -i.
Situation as follows: You work on branch 'mybranch' (locally, has not been published) and realize a while back you made a commit (revision x) that contains work that should have been separated in 2 commits. In my case that was needed because I wanted to branch from that commit the split would introduce. But in general you might want to do that to get a "nicer" history for your branch.
repo
trunk
mybranch
....
My strategy (x is the revision to split, you do the math):
bzr branch trunk mybranch-new
cd mybranch-new
bzr merge -r x ../mybranch
(revert what I don't want to have in the 1st commit)
bzr revert --forget-merges .
bzr commit -m "newly introduced commit"
bzr merge -r x ../mybranch
(resolve conflicts)
bzr revert --forget-merges .
bzr commit -m "the rest of revision x"
bzr replay -r x+1.. ../mybranch
Of course you can use this strategy to split a commit in arbitrary many smaller commits by always repeating the merge and reverting as necessary. Also by not replaying all of the remaining history, further commits can be edited.
Is this a reasonable strategy to follow or particularly intricate?
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- Bazaar Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask Florian Rathgeber for more information if necessary.