From: Jeff King <peff@peff.net>
To: Ping Yin <pkufranky@gmail.com>
Cc: git mailing list <git@vger.kernel.org>
Subject: Re: How to create a new commit with the content of some commit?
Date: Tue, 12 May 2009 12:51:03 -0400 [thread overview]
Message-ID: <20090512165103.GE29566@coredump.intra.peff.net> (raw)
In-Reply-To: <46dff0320905120943j303ef104ve7bad25f1874007f@mail.gmail.com>
On Wed, May 13, 2009 at 12:43:33AM +0800, Ping Yin wrote:
> > 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?
For some reason, I was thinking that entries in the index that were not
in "b" would remain, but that is not actually the case. So yes, I think
you can do it without removing the index (and you are better off to do
so, since the index also contains the stat cache for your worktree, so
it is more efficient).
You can also add "-u" as Junio suggested to update the working tree
during that step, which should be more efficient.
> > echo 'copy of b' >message
> > tree=`git rev-parse b^{tree}`
> > commit=`git commit-tree $tree -p c <message`
> > git update-ref c $commit
>
> Maybe a -c option can be added to git-commit-tree?
I doubt there is much interest in that, as commit-tree is meant to be a
low-level building block, not a user tool. If you wanted to pull the
message from another commit, you could just do:
git cat-file commit b | sed '1,/^$/d' | git commit-tree ...
-Peff
next prev parent reply other threads:[~2009-05-12 16:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-12 14:35 How to create a new commit with the content of some commit? Ping Yin
2009-05-12 15:47 ` Ping Yin
2009-05-12 16:04 ` Tomas Carnecky
2009-05-13 14:36 ` Sitaram Chamarty
2009-05-12 15:59 ` Junio C Hamano
2009-05-12 16:38 ` Ping Yin
2009-05-12 16:07 ` Jeff King
2009-05-12 16:43 ` Ping Yin
2009-05-12 16:51 ` Jeff King [this message]
2009-05-12 16:59 ` Ping Yin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090512165103.GE29566@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=pkufranky@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).