{"thread":{"id":"19313","subject":"How to create a new commit with the content of some commit?","startedAt":"2009-05-12T14:35:30Z","lastAt":"2009-05-13T14:36:15Z","messageCount":10,"participants":["Ping Yin","Junio C Hamano","Tomas Carnecky","Jeff King","Sitaram Chamarty"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"113637","messageId":"46dff0320905120735l501dcaf4ia8197d24b7684cfe@mail.gmail.com","threadId":"19313","inReplyTo":null,"subject":"How to create a new commit with the content of some commit?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-05-12T14:35:30Z","receivedAt":"2009-05-12T14:35:30Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"a----b\n \\----c\n\nGiven the graph above, I want to create a commit b1 on top of c, where\nb1 and b have the same content. i.e.\n\na----b\n \\----c----b1    ( content(b) == content(b1) )\n\nIf there are no untracked files in the working directory, i can do\n\ngit checkout b\ngit reset c\ngit add .\ngit commit -m \"the copy of b\"\n\nIs there any simpler way? And if there are untracked files in the\nworking directory, how to do it?\n\n\n\nPing Yin\n"},{"id":"113643","messageId":"46dff0320905120847wae71bday4d4a890b00abc222@mail.gmail.com","threadId":"19313","inReplyTo":"46dff0320905120735l501dcaf4ia8197d24b7684cfe@mail.gmail.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-05-12T15:47:42Z","receivedAt":"2009-05-12T15:47:42Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com> wrote:\n> a----b\n>  \\----c\n>\n> Given the graph above, I want to create a commit b1 on top of c, where\n> b1 and b have the same content. i.e.\n>\n> a----b\n>  \\----c----b1    ( content(b) == content(b1) )\n\nMore precisely, b1 and b point to the same tree object\n"},{"id":"113647","messageId":"7vhbzq8g7u.fsf@alter.siamese.dyndns.org","threadId":"19313","inReplyTo":"46dff0320905120735l501dcaf4ia8197d24b7684cfe@mail.gmail.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-05-12T15:59:33Z","receivedAt":"2009-05-12T15:59:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ping Yin <pkufranky@gmail.com> writes:\n\n> a----b\n>  \\----c\n>\n> Given the graph above, I want to create a commit b1 on top of c, where\n> b1 and b have the same content. i.e.\n>\n> a----b\n>  \\----c----b1    ( content(b) == content(b1) )\n\nOn \"c\", you can:\n\n    git read-tree -m -u b\n    git commit\n\nI think with newer git you can say\n\n    git reset --merge b\n    git commit\n\ninstead, to save some typing.\n"},{"id":"113650","messageId":"83048193-FBD1-4D14-9CC9-B95BD08C67F7@dbservice.com","threadId":"19313","inReplyTo":"46dff0320905120847wae71bday4d4a890b00abc222@mail.gmail.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Tomas Carnecky","fromEmail":"tom@dbservice.com","sentAt":"2009-05-12T16:04:38Z","receivedAt":"2009-05-12T16:04:38Z","isPatch":false,"sender":{"key":"tom@dbservice.com","avatar":"https://gravatar.com/avatar/900a300bdd1a8bbe086008ad78210bbee2ad2803b7d50a5cba04c1e9404bd6d2?d=mp&s=160"},"body":"\nOn May 12, 2009, at 5:47 PM, Ping Yin wrote:\n\n> On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com>  \n> wrote:\n>> a----b\n>>  \\----c\n>>\n>> Given the graph above, I want to create a commit b1 on top of c,  \n>> where\n>> b1 and b have the same content. i.e.\n>>\n>> a----b\n>>  \\----c----b1    ( content(b) == content(b1) )\n>\n> More precisely, b1 and b point to the same tree object\n\ngit checkout c\ngit cherry-pick b\n\ntom\n"},{"id":"113651","messageId":"20090512160749.GA29566@coredump.intra.peff.net","threadId":"19313","inReplyTo":"46dff0320905120735l501dcaf4ia8197d24b7684cfe@mail.gmail.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-12T16:07:49Z","receivedAt":"2009-05-12T16:07:49Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, May 12, 2009 at 10:35:30PM +0800, Ping Yin wrote:\n\n> a----b\n>  \\----c\n> \n> Given the graph above, I want to create a commit b1 on top of c, where\n> b1 and b have the same content. i.e.\n> \n> a----b\n>  \\----c----b1    ( content(b) == content(b1) )\n> \n> If there are no untracked files in the working directory, i can do\n> \n> git checkout b\n> git reset c\n> git add .\n> git commit -m \"the copy of b\"\n> \n> Is there any simpler way? And if there are untracked files in the\n> working directory, how to do it?\n\nYou can just munge the index directly, and skip the working tree\nentirely:\n\n  rm .git/index\n  git read-tree b\n  git commit -m 'the copy of b'\n\nYou would probably want to \"git checkout -f\" afterwards to update the\nworking tree with what's in the index.\n\nYou can also do it without even touching the index by using the commit\nplumbing:\n\n  echo 'copy of b' >message\n  tree=`git rev-parse b^{tree}`\n  commit=`git commit-tree $tree -p c <message`\n  git update-ref c $commit\n\n-Peff\n"},{"id":"113661","messageId":"46dff0320905120938m36018b45y780126df42ed4194@mail.gmail.com","threadId":"19313","inReplyTo":"7vhbzq8g7u.fsf@alter.siamese.dyndns.org","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-05-12T16:38:02Z","receivedAt":"2009-05-12T16:38:02Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, May 12, 2009 at 11:59 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ping Yin <pkufranky@gmail.com> writes:\n>\n>> a----b\n>>  \\----c\n>>\n>> Given the graph above, I want to create a commit b1 on top of c, where\n>> b1 and b have the same content. i.e.\n>>\n>> a----b\n>>  \\----c----b1    ( content(b) == content(b1) )\n>\n> On \"c\", you can:\n>\n>    git read-tree -m -u b\n>    git commit\n\nis -u necessary?\n\n>\n> I think with newer git you can say\n>\n>    git reset --merge b\n>    git commit\n>\n\nWhen the working directory is clean, it seems \"reset --hard\" and\n\"reset --merge\" behave the same. So after \"git reset --merge b\",  the\nHEAD is moved to b, and i have nothing to commit.\n"},{"id":"113663","messageId":"46dff0320905120943j303ef104ve7bad25f1874007f@mail.gmail.com","threadId":"19313","inReplyTo":"20090512160749.GA29566@coredump.intra.peff.net","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-05-12T16:43:33Z","receivedAt":"2009-05-12T16:43:33Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Wed, May 13, 2009 at 12:07 AM, Jeff King <peff@peff.net> wrote:\n> On Tue, May 12, 2009 at 10:35:30PM +0800, Ping Yin wrote:\n>\n>> a----b\n>>  \\----c\n>>\n>> Given the graph above, I want to create a commit b1 on top of c, where\n>> b1 and b have the same content. i.e.\n>>\n>> a----b\n>>  \\----c----b1    ( content(b) == content(b1) )\n>>\n>> If there are no untracked files in the working directory, i can do\n>>\n>> git checkout b\n>> git reset c\n>> git add .\n>> git commit -m \"the copy of b\"\n>>\n>> Is there any simpler way? And if there are untracked files in the\n>> working directory, how to do it?\n>\n> You can just munge the index directly, and skip the working tree\n> entirely:\n>\n>  rm .git/index\n>  git read-tree b\n>  git commit -m 'the copy of b'\n\nIn a non-conflict status, \"git read-tree b\" will update the index to\nfull match the tree of b, so \"rm .git/index\" is unnecessary, right?\n\n\n> You can also do it without even touching the index by using the commit\n> plumbing:\n>\n>  echo 'copy of b' >message\n>  tree=`git rev-parse b^{tree}`\n>  commit=`git commit-tree $tree -p c <message`\n>  git update-ref c $commit\n\nNice solution. Thank you and thank so powerful git!\n\nMaybe a -c option can be added to git-commit-tree?\n"},{"id":"113665","messageId":"20090512165103.GE29566@coredump.intra.peff.net","threadId":"19313","inReplyTo":"46dff0320905120943j303ef104ve7bad25f1874007f@mail.gmail.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-05-12T16:51:03Z","receivedAt":"2009-05-12T16:51:03Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, May 13, 2009 at 12:43:33AM +0800, Ping Yin wrote:\n\n> > You can just munge the index directly, and skip the working tree\n> > entirely:\n> >\n> >  rm .git/index\n> >  git read-tree b\n> >  git commit -m 'the copy of b'\n> \n> In a non-conflict status, \"git read-tree b\" will update the index to\n> full match the tree of b, so \"rm .git/index\" is unnecessary, right?\n\nFor some reason, I was thinking that entries in the index that were not\nin \"b\" would remain, but that is not actually the case. So yes, I think\nyou can do it without removing the index (and you are better off to do\nso, since the index also contains the stat cache for your worktree, so\nit is more efficient).\n\nYou can also add \"-u\" as Junio suggested to update the working tree\nduring that step, which should be more efficient.\n\n> >  echo 'copy of b' >message\n> >  tree=`git rev-parse b^{tree}`\n> >  commit=`git commit-tree $tree -p c <message`\n> >  git update-ref c $commit\n> \n> Maybe a -c option can be added to git-commit-tree?\n\nI doubt there is much interest in that, as commit-tree is meant to be a\nlow-level building block, not a user tool. If you wanted to pull the\nmessage from another commit, you could just do:\n\n  git cat-file commit b | sed '1,/^$/d' | git commit-tree ...\n\n-Peff\n"},{"id":"113668","messageId":"46dff0320905120959sc69eec9h23cd8ac6b489e5b6@mail.gmail.com","threadId":"19313","inReplyTo":"20090512165103.GE29566@coredump.intra.peff.net","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2009-05-12T16:59:50Z","receivedAt":"2009-05-12T16:59:50Z","isPatch":false,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Wed, May 13, 2009 at 12:51 AM, Jeff King <peff@peff.net> wrote:\n> On Wed, May 13, 2009 at 12:43:33AM +0800, Ping Yin wrote:\n>\n>> > You can just munge the index directly, and skip the working tree\n>> > entirely:\n>> >\n>> >  rm .git/index\n>> >  git read-tree b\n>> >  git commit -m 'the copy of b'\n>>\n>> In a non-conflict status, \"git read-tree b\" will update the index to\n>> full match the tree of b, so \"rm .git/index\" is unnecessary, right?\n>\n> For some reason, I was thinking that entries in the index that were not\n> in \"b\" would remain, but that is not actually the case. So yes, I think\n> you can do it without removing the index (and you are better off to do\n> so, since the index also contains the stat cache for your worktree, so\n> it is more efficient).\n>\n> You can also add \"-u\" as Junio suggested to update the working tree\n> during that step, which should be more efficient.\n\nI don't want to touch the working directory, and -m will keep the stat\ncache in the index, so i think \"git read-tree -m b\" is the best.\n"},{"id":"113791","messageId":"slrnh0lmmv.5j5.sitaramc@sitaramc.homelinux.net","threadId":"19313","inReplyTo":"83048193-FBD1-4D14-9CC9-B95BD08C67F7@dbservice.com","subject":"Re: How to create a new commit with the content of some commit?","fromName":"Sitaram Chamarty","fromEmail":"sitaramc@gmail.com","sentAt":"2009-05-13T14:36:15Z","receivedAt":"2009-05-13T14:36:15Z","isPatch":false,"sender":{"key":"sitaramc@gmail.com","avatar":"https://avatars.githubusercontent.com/u/43316?v=4"},"body":"On 2009-05-12, Tomas Carnecky <tom@dbservice.com> wrote:\n>\n> On May 12, 2009, at 5:47 PM, Ping Yin wrote:\n>\n>> On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com>  \n>> wrote:\n>>> a----b\n>>>  \\----c\n>>>\n>>> Given the graph above, I want to create a commit b1 on top of c,  \n>>> where\n>>> b1 and b have the same content. i.e.\n>>>\n>>> a----b\n>>>  \\----c----b1    ( content(b) == content(b1) )\n>>\n>> More precisely, b1 and b point to the same tree object\n>\n> git checkout c\n> git cherry-pick b\n\nI do not think this does what was wanted.  Applying the\nchange from a->b onto c may not give you \"b\" unless a==c.\n"}]}