threads / discuss / 20168

how to reorder commits

Subject: how to reorder commits

## tl;dr

6 messages between Jul 20, 2009 and Jul 21, 2009.

replies: 5people: 3as markdown or json

Rustom Mody· Jul 20, 2009, 15:07 UTC · lore

I have a sequence of commits. I tried to reorder the top two in this way. $ git rebase -i HEAD^^

flip the two pick lines and exit vi

I find my file full of conflict markers. So what is the way of doing: HEAD becomes current HEAD^ HEAD^ becomes current HEAD without having to handle conflicts ??

Santi Béjar· Jul 20, 2009, 15:37 UTC · re: Rustom Mody · lore

Re: how to reorder commits

2009/7/20 Rustom Mody <rustompmody@gmail.com>:
Show 6 quoted lines
> I have a sequence of commits. I tried to reorder the top two in this way.
> $ git rebase -i HEAD^^
>
> flip the two pick lines and exit vi
>
> I find my file full of conflict markers.

"git rebase" applies the changes between the commit and the parent, and if the changes have conflicts this is what you get.

> So what is the way of doing:
> HEAD becomes current HEAD^
> HEAD^ becomes current HEAD

$ git branch old $ git reset --hard HEAD~2 $ git read-tree old $ git commit -C old $ git read-tree old^ $ git commit -C old^

But normally you reorder "changes", not trees.

HTH, Santi

Rustom Mody· Jul 20, 2009, 16:01 UTC · re: Santi Béjar · lore

Re: how to reorder commits

On Mon, Jul 20, 2009 at 9:07 PM, Santi Béjar<santi@agolina.net> wrote:
Show 21 quoted lines
> 2009/7/20 Rustom Mody <rustompmody@gmail.com>:
>> I have a sequence of commits. I tried to reorder the top two in this way.
>> $ git rebase -i HEAD^^
>>
>> flip the two pick lines and exit vi
>>
>> I find my file full of conflict markers.
>
> "git rebase" applies the changes between the commit and the parent,
> and if the changes have conflicts this is what you get.
>
>> So what is the way of doing:
>> HEAD becomes current HEAD^
>> HEAD^ becomes current HEAD
>
> $ git branch old
> $ git reset --hard HEAD~2
> $ git read-tree old
> $ git commit -C old
> $ git read-tree old^
> $ git commit -C old^
Beautiful -- plumbing is nifty!
>
> But normally you reorder "changes", not trees.
Which may not always be conflict-free?
Santi Béjar· Jul 20, 2009, 16:16 UTC · re: Rustom Mody · lore

Re: how to reorder commits

2009/7/20 Rustom Mody <rustompmody@gmail.com>:
> On Mon, Jul 20, 2009 at 9:07 PM, Santi Béjar<santi@agolina.net> wrote:
>> But normally you reorder "changes", not trees.
>
> Which may not always be conflict-free?

No. But the fact that there is no porcelain way to do it may show that reordering trees is not what you normally want, even if reordering trees is conflict-free.

HTH, Santi

Daniel Barkalow· Jul 20, 2009, 21:27 UTC · re: Rustom Mody · lore

Re: how to reorder commits

On Mon, 20 Jul 2009, Rustom Mody wrote:
Show 10 quoted lines
> I have a sequence of commits. I tried to reorder the top two in this way.
> $ git rebase -i HEAD^^
> 
> flip the two pick lines and exit vi
> 
> I find my file full of conflict markers.
> So what is the way of doing:
> HEAD becomes current HEAD^
> HEAD^ becomes current HEAD
> without having to handle conflicts ??

Note that what you're asking for here would add both changes in HEAD^ and *remove* some changes in HEAD (to get to the state where only the change that was made first has been made).

What you tried with rebase is correct, but if your changes in those commits intersect, impossible to do automatically:

Original:
 This is an example.
Change 1:

-This is an example. +This is a better example.

Change 2:

-This is a better example. +This is a better sentence.

Now, make change 2 without change 1. Even if you can split the changes as (1) "an"->"a better"; (2) "example"->"sentence", you get:

 This is an sentence.
When the correct version would be:
 This is a sentence.
But there's no automated way to know this, so you get conflict markers.
	-Daniel
*This .sig left intentionally blank*
Rustom Mody· Jul 21, 2009, 07:53 UTC · lore

Re: how to reorder commits

On Tue, Jul 21, 2009 at 2:31 AM, David Kågedal<david@kagedal.org> wrote:
Show 6 quoted lines
>
> Latest stgit actually has it. You can push a patch with the --set-tree
> flag. So your sequence of commands would have been (with the latest
> two commits as stg patches called "old" and "older")
>
> $ stg series
... example snipped ...

Thanks for the info but I gather that stgit does not run on windows? I need git to run on both on linux and windows.

← back to recent threads