{"thread":{"id":"33524","subject":"Splitting a commit with rebase -i and keeping a commit message","startedAt":"2013-04-17T01:38:25Z","lastAt":"2013-04-17T05:55:41Z","messageCount":4,"participants":["Tim Chase","David Aguilar","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"214564","messageId":"20130416203825.3701d98b@bigbox.christie.dr","threadId":"33524","inReplyTo":null,"subject":"Splitting a commit with rebase -i and keeping a commit message","fromName":"Tim Chase","fromEmail":"git@tim.thechases.com","sentAt":"2013-04-17T01:38:25Z","receivedAt":"2013-04-17T01:38:25Z","isPatch":false,"sender":{"key":"git@tim.thechases.com","avatar":null},"body":"I asked this on IRC and played with some of their ideas, but struck\nout with anything satisfying.  I walked through [1] with the\nfollowing setup:\n\n  git init foo\n  cd foo\n  touch a.txt b.txt\n  git add a.txt b.txt\n  git commit -m \"Initial checkin\"\n  echo \"Modify A\" >> a.txt\n  git commit -am \"Modified A\"\n  echo \"Modify B\" >> b.txt\n  git commit -am \"Modified B\"\n  echo \"Modify A2\" >> a.txt\n  echo \"Modify B2\" >> b.txt\n  git commit -am \"Modified B\"\n  git commit -am \"Long-bodied commit comment about b.txt changes\"\n  # whoops, just wanted B\n  git rebase -i HEAD^^\n  # change the \"Added b.txt...\" commit to \"edit\"\n  git reset HEAD^  # pull the changes out of the pending commit\n  git add a.txt\n  git commit -m \"Tweaked a.txt\"\n  git add b.txt\n  git commit ${MAGIC_HERE}\n  git rebase --continue\n\nI haven't been able to figure out a good way to keep the \"long-bodied\ncommit comment\" for the final commit where the ${MAGIC_HERE} is.  Is\nthere a right/easy way to go about pulling in the commit-message from\nthe commit the rebase is transplanting?\n\n-tkc\n\n[1]\nhttp://git-scm.com/book/en/Git-Tools-Rewriting-History#Splitting-a-Commit\n"},{"id":"214565","messageId":"CAJDDKr64KpF-DP5Axj+vhxRQ1rrig=pm25T3Angp8GaKK_CHMA@mail.gmail.com","threadId":"33524","inReplyTo":"20130416203825.3701d98b@bigbox.christie.dr","subject":"Re: Splitting a commit with rebase -i and keeping a commit message","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2013-04-17T02:29:47Z","receivedAt":"2013-04-17T02:29:47Z","isPatch":false,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Taking a wild guess here...\n\nOn Tue, Apr 16, 2013 at 6:38 PM, Tim Chase <git@tim.thechases.com> wrote:\n> I asked this on IRC and played with some of their ideas, but struck\n> out with anything satisfying.  I walked through [1] with the\n> following setup:\n>\n>   git init foo\n>   cd foo\n>   touch a.txt b.txt\n>   git add a.txt b.txt\n>   git commit -m \"Initial checkin\"\n>   echo \"Modify A\" >> a.txt\n>   git commit -am \"Modified A\"\n>   echo \"Modify B\" >> b.txt\n>   git commit -am \"Modified B\"\n>   echo \"Modify A2\" >> a.txt\n>   echo \"Modify B2\" >> b.txt\n>   git commit -am \"Modified B\"\n>   git commit -am \"Long-bodied commit comment about b.txt changes\"\n>   # whoops, just wanted B\n\nSave the commit's ID here so that we can reuse its message later:\n\n    orig_commit=$(git rev-parse HEAD)\n\n>   git rebase -i HEAD^^\n>   # change the \"Added b.txt...\" commit to \"edit\"\n>   git reset HEAD^  # pull the changes out of the pending commit\n>   git add a.txt\n>   git commit -m \"Tweaked a.txt\"\n>   git add b.txt\n>   git commit ${MAGIC_HERE}\n\n...reuse the commit message by passing the \"-c\" option to \"git commit\":\n\n    git commit --reset-author -c $orig_commit\n\nThis will give you a chance to further edit the message in your editor.\n\n>   git rebase --continue\n>\n> I haven't been able to figure out a good way to keep the \"long-bodied\n> commit comment\" for the final commit where the ${MAGIC_HERE} is.  Is\n> there a right/easy way to go about pulling in the commit-message from\n> the commit the rebase is transplanting?\n\nThis is pretty much what the commands above do.\nThey save the commit ID so that we can reuse the message later.\n\nHTH,\n--\nDavid\n"},{"id":"214567","messageId":"20130416220407.105b354e@bigbox.christie.dr","threadId":"33524","inReplyTo":"CAJDDKr64KpF-DP5Axj+vhxRQ1rrig=pm25T3Angp8GaKK_CHMA@mail.gmail.com","subject":"Re: Splitting a commit with rebase -i and keeping a commit message","fromName":"Tim Chase","fromEmail":"git@tim.thechases.com","sentAt":"2013-04-17T03:04:07Z","receivedAt":"2013-04-17T03:04:07Z","isPatch":false,"sender":{"key":"git@tim.thechases.com","avatar":null},"body":"On 2013-04-16 19:29, David Aguilar wrote:\n> On Tue, Apr 16, 2013 at 6:38 PM, Tim Chase <git@tim.thechases.com>\n> wrote:\n> >   git commit -am \"Long-bodied commit comment about b.txt changes\"\n> >   # whoops, just wanted B\n> \n> Save the commit's ID here so that we can reuse its message later:\n> \n>     orig_commit=$(git rev-parse HEAD)\n> \n> >   git rebase -i HEAD^^\n> >   # change the \"Added b.txt...\" commit to \"edit\"\n> >   git reset HEAD^  # pull the changes out of the pending commit\n> >   git add a.txt\n> >   git commit -m \"Tweaked a.txt\"\n> >   git add b.txt\n> >   git commit ${MAGIC_HERE}\n> \n> ...reuse the commit message by passing the \"-c\" option to \"git\n> commit\":\n> \n>     git commit --reset-author -c $orig_commit\n\nWild guess or not, using -c worked great.  With the appropriate\nsection of the docs now in hand, I discovered that it could even be\nsimplified to just\n\n  git commit -c ORIG_HEAD [...]\n\nas rebase stashes that information away for me already as \"ORIG_HEAD\".\n\nThanks!\n\n-tkc\n"},{"id":"214579","messageId":"516E395D.3050307@viscovery.net","threadId":"33524","inReplyTo":"20130416203825.3701d98b@bigbox.christie.dr","subject":"Re: Splitting a commit with rebase -i and keeping a commit message","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2013-04-17T05:55:41Z","receivedAt":"2013-04-17T05:55:41Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 4/17/2013 3:38, schrieb Tim Chase:\n> I asked this on IRC and played with some of their ideas, but struck\n> out with anything satisfying.  I walked through [1] with the\n> following setup:\n> \n>   git init foo\n>   cd foo\n>   touch a.txt b.txt\n>   git add a.txt b.txt\n>   git commit -m \"Initial checkin\"\n>   echo \"Modify A\" >> a.txt\n>   git commit -am \"Modified A\"\n>   echo \"Modify B\" >> b.txt\n>   git commit -am \"Modified B\"\n>   echo \"Modify A2\" >> a.txt\n>   echo \"Modify B2\" >> b.txt\n>   git commit -am \"Modified B\"\n>   git commit -am \"Long-bodied commit comment about b.txt changes\"\n>   # whoops, just wanted B\n>   git rebase -i HEAD^^\n>   # change the \"Added b.txt...\" commit to \"edit\"\n\n    # and duplicate the instruction line\n    git checkout HEAD^ b.txt # undo b.txt\n    git commit --amend -m \"Tweaked a.txt\"\n    git rebase --continue\n    # in real world cases, you are likely to see conflicts here\n    # when the commit is applied a second time,\n    # but not in this toy example\n    git rebase --continue\n\n-- Hannes\n"}]}