Skip to contentSkip to conversation

how to reorder commits

DISCUSSION Rustom Mody 3 participants 6 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

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 ??

#1 lore raw

2009/7/20 Rustom Mody <[email protected]>:

Quoted 6 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.

Quoted 3 lines

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

#2 lore raw
Quoted 15 lines · Santi Béjar

2009/7/20 Rustom Mody <[email protected]>:

Quoted 6 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.

Quoted 3 lines

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

Quoted 6 lines
$ 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!

Quoted 2 lines

But normally you reorder "changes", not trees.

Which may not always be conflict-free?

#3 lore raw

2009/7/20 Rustom Mody <[email protected]>:

Quoted 4 lines · Santi Béjar
Quoted 1 line

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 6 lines · David Kågedal

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.

#6 lore raw
In reply to Rustom Mody
Quoted 10 lines · Rustom Mody

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*