{"thread":{"id":"29979","subject":"How to reorder all commits include the initial commit","startedAt":"2012-03-17T13:15:56Z","lastAt":"2012-03-18T19:05:14Z","messageCount":6,"participants":["이응준","David Barr","Jakub Narebski","Yi, EungJun","Jiang Xin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"187148","messageId":"CAFT+Tg_DmqxiK1qw1YvNZtY07ZaZ89+JWohdWw2fm8f=6hAwiQ@mail.gmail.com","threadId":"29979","inReplyTo":null,"subject":"How to reorder all commits include the initial commit","fromName":"이응준","fromEmail":"semtlenori@gmail.com","sentAt":"2012-03-17T13:15:56Z","receivedAt":"2012-03-17T13:15:56Z","isPatch":false,"sender":{"key":"semtlenori@gmail.com","avatar":"https://gravatar.com/avatar/8363435d2badb3450df0dd7c4ec2113f6e1d62c44dd3cf7dfe83c5a389b8a9bf?d=mp&s=160"},"body":"Sometimes, I need to reorder all commits, which include the initial\ncommit, in my branch.\nSo I tried it using git-rebase as follows, but it failed with the fatal error.\n\n(supposing the initial commit is 793ea88)\n$ git rebase -i 793ea88^\nfatal: Needed a single revision\ninvalid upstream 793ea88^\n\nHow can I do that?\n"},{"id":"187151","messageId":"CAFfmPPOhjDhdry2yqgSyAVhaPF-fhXOPOAWRahFkFFssQmz89A@mail.gmail.com","threadId":"29979","inReplyTo":"CAFT+Tg_DmqxiK1qw1YvNZtY07ZaZ89+JWohdWw2fm8f=6hAwiQ@mail.gmail.com","subject":"Re: How to reorder all commits include the initial commit","fromName":"David Barr","fromEmail":"davidbarr@google.com","sentAt":"2012-03-17T14:06:56Z","receivedAt":"2012-03-17T14:06:56Z","isPatch":false,"sender":{"key":"davidbarr@google.com","avatar":"https://avatars.githubusercontent.com/u/220594?v=4"},"body":"On Sun, Mar 18, 2012 at 12:15 AM, 이응준 <semtlenori@gmail.com> wrote:\n> Sometimes, I need to reorder all commits, which include the initial\n> commit, in my branch.\n> So I tried it using git-rebase as follows, but it failed with the fatal error.\n>\n> (supposing the initial commit is 793ea88)\n> $ git rebase -i 793ea88^\n> fatal: Needed a single revision\n> invalid upstream 793ea88^\n>\n> How can I do that?\n\nFrom my reading of git-rebase(1), this is currently unsupported.\nHowever, I was able to reorder linear history including the root using\ngit format-patch and git am.\n\n  git init test\n  cd test/\n  echo a>b\n  git add b\n  git commit -m '1'\n  echo c>d\n  git add d\n  git commit -m '2'\n  git init new\n  cd new/\n  git am ../0002-2.patch\n  git am ../0001-1.patch\n\n--\nDavid Barr\n"},{"id":"187154","messageId":"m3k42jl2wn.fsf@localhost.localdomain","threadId":"29979","inReplyTo":"CAFT+Tg_DmqxiK1qw1YvNZtY07ZaZ89+JWohdWw2fm8f=6hAwiQ@mail.gmail.com","subject":"Re: How to reorder all commits include the initial commit","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2012-03-17T14:26:18Z","receivedAt":"2012-03-17T14:26:18Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"semtlenori@gmail.com writes:\n\n> Sometimes, I need to reorder all commits, which include the initial\n> commit, in my branch.\n> So I tried it using git-rebase as follows, but it failed with the fatal error.\n> \n> (supposing the initial commit is 793ea88)\n> $ git rebase -i 793ea88^\n> fatal: Needed a single revision\n> invalid upstream 793ea88^\n> \n> How can I do that?\n\nUse `--root` option.\n\n-- \nJakub Narebski\n"},{"id":"187173","messageId":"CAFT+Tg9UGdBxj5-DTpxDJRVgvBCnmkmgm6nzVek0KeELgsNneQ@mail.gmail.com","threadId":"29979","inReplyTo":"m3k42jl2wn.fsf@localhost.localdomain","subject":"Re: How to reorder all commits include the initial commit","fromName":"Yi, EungJun","fromEmail":"semtlenori@gmail.com","sentAt":"2012-03-17T19:45:15Z","receivedAt":"2012-03-17T19:45:15Z","isPatch":false,"sender":{"key":"semtlenori@gmail.com","avatar":"https://gravatar.com/avatar/8363435d2badb3450df0dd7c4ec2113f6e1d62c44dd3cf7dfe83c5a389b8a9bf?d=mp&s=160"},"body":"Thanks to David Barr and Jakub Narebski.\nFinally I found the way based on your hints to solve my problem.\n\n$ git checkout -b test --orphan\n$ git format-patch <newroot>^..<newroot> | git am\n$ git rebase -i --onto test --root master\n$ git branch -M test master\n\nPlease let me know if there is more simple way.\n\n2012년 3월 17일 오후 11:26, Jakub Narebski <jnareb@gmail.com>님의 말:\n> semtlenori@gmail.com writes:\n>\n>> Sometimes, I need to reorder all commits, which include the initial\n>> commit, in my branch.\n>> So I tried it using git-rebase as follows, but it failed with the fatal error.\n>>\n>> (supposing the initial commit is 793ea88)\n>> $ git rebase -i 793ea88^\n>> fatal: Needed a single revision\n>> invalid upstream 793ea88^\n>>\n>> How can I do that?\n>\n> Use `--root` option.\n>\n> --\n> Jakub Narebski\n>\n"},{"id":"187192","messageId":"CANYiYbGbJxZPOAN9twBPZoD318eA_CLcsVzcFuoHrc32+e96FQ@mail.gmail.com","threadId":"29979","inReplyTo":"CAFT+Tg9UGdBxj5-DTpxDJRVgvBCnmkmgm6nzVek0KeELgsNneQ@mail.gmail.com","subject":"Re: How to reorder all commits include the initial commit","fromName":"Jiang Xin","fromEmail":"worldhello.net@gmail.com","sentAt":"2012-03-18T02:58:05Z","receivedAt":"2012-03-18T02:58:05Z","isPatch":false,"sender":{"key":"worldhello.net@gmail.com","avatar":"https://avatars.githubusercontent.com/u/183860?v=4"},"body":"2012/3/18 Yi, EungJun <semtlenori@gmail.com>:\n> Thanks to David Barr and Jakub Narebski.\n> Finally I found the way based on your hints to solve my problem.\n>\n> $ git checkout -b test --orphan\n\noption -b and --orphan can not be used together.\n\n> $ git format-patch <newroot>^..<newroot> | git am\n\ncan not apply patch when there is no root commit\n\nMy test for your case:\n\nlog of master branch before rebase:\n\n    $ git log --oneline\n    1a91ece commit 3\n    d7c6dec commit 2\n    e32542d commit 1\n\nrebase:\n\n    $ git checkout --orphan new-master\n    $ rm .git/index\n    $ git commit --allow-empty -m initial\n    $ git clean -fd\n    $ git cherry-pick -n master^\n    $ git commit --amend -C master^\n    $ git rebase --root --onto new-master master\n    $ git branch -d new-master\n\nmaster after rebase:\n\n    $ git log --oneline\n    fbb9fb6 commit 3\n    56afd5c commit 1\n    894c42a commit 2\n\n--\nJiang Xin\n"},{"id":"187213","messageId":"CAFT+Tg8=dkFLh_=2pMYH6McZTWr2NjxZHztVG7WcxGMEBmdOwA@mail.gmail.com","threadId":"29979","inReplyTo":"CANYiYbGbJxZPOAN9twBPZoD318eA_CLcsVzcFuoHrc32+e96FQ@mail.gmail.com","subject":"Re: How to reorder all commits include the initial commit","fromName":"Yi, EungJun","fromEmail":"semtlenori@gmail.com","sentAt":"2012-03-18T19:05:14Z","receivedAt":"2012-03-18T19:05:14Z","isPatch":false,"sender":{"key":"semtlenori@gmail.com","avatar":"https://gravatar.com/avatar/8363435d2badb3450df0dd7c4ec2113f6e1d62c44dd3cf7dfe83c5a389b8a9bf?d=mp&s=160"},"body":"2012년 3월 18일 오전 11:58, Jiang Xin <worldhello.net@gmail.com>님의 말:\n>> $ git checkout -b test --orphan\n>\n> option -b and --orphan can not be used together.\n>\n>> $ git format-patch <newroot>^..<newroot> | git am\n>\n> can not apply patch when there is no root commit\n>\n\nYou are all right. I made several mistakes including what you point out.\n\nI fixed them as follows:\n\n$ git checkout --orphan test\n$ git rm '*' -f\n$ git show <newroot> | git apply - --index\n$ git commit --reuse-message <newroot>\n$ git rebase --onto test --root master\n$ git branch -d test\n"}]}