git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* How to reorder all commits include the initial commit
@ 2012-03-17 13:15 이응준
  2012-03-17 14:06 ` David Barr
  2012-03-17 14:26 ` Jakub Narebski
  0 siblings, 2 replies; 6+ messages in thread
From: 이응준 @ 2012-03-17 13:15 UTC (permalink / raw)
  To: git

Sometimes, I need to reorder all commits, which include the initial
commit, in my branch.
So I tried it using git-rebase as follows, but it failed with the fatal error.

(supposing the initial commit is 793ea88)
$ git rebase -i 793ea88^
fatal: Needed a single revision
invalid upstream 793ea88^

How can I do that?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to reorder all commits include the initial commit
  2012-03-17 13:15 How to reorder all commits include the initial commit 이응준
@ 2012-03-17 14:06 ` David Barr
  2012-03-17 14:26 ` Jakub Narebski
  1 sibling, 0 replies; 6+ messages in thread
From: David Barr @ 2012-03-17 14:06 UTC (permalink / raw)
  To: semtlenori; +Cc: git

On Sun, Mar 18, 2012 at 12:15 AM, 이응준 <semtlenori@gmail.com> wrote:
> Sometimes, I need to reorder all commits, which include the initial
> commit, in my branch.
> So I tried it using git-rebase as follows, but it failed with the fatal error.
>
> (supposing the initial commit is 793ea88)
> $ git rebase -i 793ea88^
> fatal: Needed a single revision
> invalid upstream 793ea88^
>
> How can I do that?

From my reading of git-rebase(1), this is currently unsupported.
However, I was able to reorder linear history including the root using
git format-patch and git am.

  git init test
  cd test/
  echo a>b
  git add b
  git commit -m '1'
  echo c>d
  git add d
  git commit -m '2'
  git init new
  cd new/
  git am ../0002-2.patch
  git am ../0001-1.patch

--
David Barr

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to reorder all commits include the initial commit
  2012-03-17 13:15 How to reorder all commits include the initial commit 이응준
  2012-03-17 14:06 ` David Barr
@ 2012-03-17 14:26 ` Jakub Narebski
  2012-03-17 19:45   ` Yi, EungJun
  1 sibling, 1 reply; 6+ messages in thread
From: Jakub Narebski @ 2012-03-17 14:26 UTC (permalink / raw)
  To: semtlenori; +Cc: git

semtlenori@gmail.com writes:

> Sometimes, I need to reorder all commits, which include the initial
> commit, in my branch.
> So I tried it using git-rebase as follows, but it failed with the fatal error.
> 
> (supposing the initial commit is 793ea88)
> $ git rebase -i 793ea88^
> fatal: Needed a single revision
> invalid upstream 793ea88^
> 
> How can I do that?

Use `--root` option.

-- 
Jakub Narebski

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to reorder all commits include the initial commit
  2012-03-17 14:26 ` Jakub Narebski
@ 2012-03-17 19:45   ` Yi, EungJun
  2012-03-18  2:58     ` Jiang Xin
  0 siblings, 1 reply; 6+ messages in thread
From: Yi, EungJun @ 2012-03-17 19:45 UTC (permalink / raw)
  To: Jakub Narebski; +Cc: git

Thanks to David Barr and Jakub Narebski.
Finally I found the way based on your hints to solve my problem.

$ git checkout -b test --orphan
$ git format-patch <newroot>^..<newroot> | git am
$ git rebase -i --onto test --root master
$ git branch -M test master

Please let me know if there is more simple way.

2012년 3월 17일 오후 11:26, Jakub Narebski <jnareb@gmail.com>님의 말:
> semtlenori@gmail.com writes:
>
>> Sometimes, I need to reorder all commits, which include the initial
>> commit, in my branch.
>> So I tried it using git-rebase as follows, but it failed with the fatal error.
>>
>> (supposing the initial commit is 793ea88)
>> $ git rebase -i 793ea88^
>> fatal: Needed a single revision
>> invalid upstream 793ea88^
>>
>> How can I do that?
>
> Use `--root` option.
>
> --
> Jakub Narebski
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to reorder all commits include the initial commit
  2012-03-17 19:45   ` Yi, EungJun
@ 2012-03-18  2:58     ` Jiang Xin
  2012-03-18 19:05       ` Yi, EungJun
  0 siblings, 1 reply; 6+ messages in thread
From: Jiang Xin @ 2012-03-18  2:58 UTC (permalink / raw)
  To: semtlenori; +Cc: Jakub Narebski, git

2012/3/18 Yi, EungJun <semtlenori@gmail.com>:
> Thanks to David Barr and Jakub Narebski.
> Finally I found the way based on your hints to solve my problem.
>
> $ git checkout -b test --orphan

option -b and --orphan can not be used together.

> $ git format-patch <newroot>^..<newroot> | git am

can not apply patch when there is no root commit

My test for your case:

log of master branch before rebase:

    $ git log --oneline
    1a91ece commit 3
    d7c6dec commit 2
    e32542d commit 1

rebase:

    $ git checkout --orphan new-master
    $ rm .git/index
    $ git commit --allow-empty -m initial
    $ git clean -fd
    $ git cherry-pick -n master^
    $ git commit --amend -C master^
    $ git rebase --root --onto new-master master
    $ git branch -d new-master

master after rebase:

    $ git log --oneline
    fbb9fb6 commit 3
    56afd5c commit 1
    894c42a commit 2

--
Jiang Xin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to reorder all commits include the initial commit
  2012-03-18  2:58     ` Jiang Xin
@ 2012-03-18 19:05       ` Yi, EungJun
  0 siblings, 0 replies; 6+ messages in thread
From: Yi, EungJun @ 2012-03-18 19:05 UTC (permalink / raw)
  To: Jiang Xin; +Cc: Jakub Narebski, git

2012년 3월 18일 오전 11:58, Jiang Xin <worldhello.net@gmail.com>님의 말:
>> $ git checkout -b test --orphan
>
> option -b and --orphan can not be used together.
>
>> $ git format-patch <newroot>^..<newroot> | git am
>
> can not apply patch when there is no root commit
>

You are all right. I made several mistakes including what you point out.

I fixed them as follows:

$ git checkout --orphan test
$ git rm '*' -f
$ git show <newroot> | git apply - --index
$ git commit --reuse-message <newroot>
$ git rebase --onto test --root master
$ git branch -d test

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-18 19:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-17 13:15 How to reorder all commits include the initial commit 이응준
2012-03-17 14:06 ` David Barr
2012-03-17 14:26 ` Jakub Narebski
2012-03-17 19:45   ` Yi, EungJun
2012-03-18  2:58     ` Jiang Xin
2012-03-18 19:05       ` Yi, EungJun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).