Rewrite / edit a commit earlier in history

Asked by Florian Rathgeber

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:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#2

Does no answer mean there isn't an easier way?

Revision history for this message
John A Meinel (jameinel) said :
#3

There is the 'bzr-rewrite' plugin, which provides some commands like rebase/replay to help creating a new history that is similar to the old one. But your method seems fine when you want to preserve the old history as much as possible.

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#4

I looked at the rewrite plugin (and my strategy uses replay), but couldn't
find an easier solution preserving history. Is there a more comfortable way
if I'd be willing to sacrifice a bit?
On 6 Jul 2011 13:46, "John A Meinel" <email address hidden>
wrote:
> Your question #161112 on Bazaar changed:
> https://answers.launchpad.net/bzr/+question/161112
>
> Status: Open => Answered
>
> John A Meinel proposed the following answer:
> There is the 'bzr-rewrite' plugin, which provides some commands like
> rebase/replay to help creating a new history that is similar to the old
> one. But your method seems fine when you want to preserve the old
> history as much as possible.
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/bzr/+question/161112/+confirm?answer_id=2
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/bzr/+question/161112
>
> You received this question notification because you asked the question.

Revision history for this message
Launchpad Janitor (janitor) said :
#5

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#6

Revive s.t. it appears in listings (since it has been answered).

Revision history for this message
Florian Rathgeber (florian-rathgeber) said :
#7

Sorry, that hasn't worked. Could this question be marked as answered instead of expired?

Revision history for this message
Jelmer Vernooij (jelmer) said :
#8

.

Can you help with this problem?

Provide an answer of your own, or ask Florian Rathgeber for more information if necessary.

To post a message you must log in.