From: Ping Yin Date: Tue, 12 May 2009 16:43:33 GMT Subject: Re: How to create a new commit with the content of some commit? Message-ID: <46dff0320905120943j303ef104ve7bad25f1874007f@mail.gmail.com> In-Reply-To: <20090512160749.GA29566@coredump.intra.peff.net> On Wed, May 13, 2009 at 12:07 AM, Jeff King wrote: > On Tue, May 12, 2009 at 10:35:30PM +0800, Ping Yin wrote: > >> a----b >>  \----c >> >> Given the graph above, I want to create a commit b1 on top of c, where >> b1 and b have the same content. i.e. >> >> a----b >>  \----c----b1    ( content(b) == content(b1) ) >> >> If there are no untracked files in the working directory, i can do >> >> git checkout b >> git reset c >> git add . >> git commit -m "the copy of b" >> >> Is there any simpler way? And if there are untracked files in the >> working directory, how to do it? > > You can just munge the index directly, and skip the working tree > entirely: > >  rm .git/index >  git read-tree b >  git commit -m 'the copy of b' In a non-conflict status, "git read-tree b" will update the index to full match the tree of b, so "rm .git/index" is unnecessary, right? > You can also do it without even touching the index by using the commit > plumbing: > >  echo 'copy of b' >message >  tree=`git rev-parse b^{tree}` >  commit=`git commit-tree $tree -p c  git update-ref c $commit Nice solution. Thank you and thank so powerful git! Maybe a -c option can be added to git-commit-tree?