git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* How to create a new commit with the content of some commit?
@ 2009-05-12 14:35 Ping Yin
  2009-05-12 15:47 ` Ping Yin
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Ping Yin @ 2009-05-12 14:35 UTC (permalink / raw)
  To: git mailing list

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?



Ping Yin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  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-12 15:59 ` Junio C Hamano
  2009-05-12 16:07 ` Jeff King
  2 siblings, 1 reply; 10+ messages in thread
From: Ping Yin @ 2009-05-12 15:47 UTC (permalink / raw)
  To: git mailing list

On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com> 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) )

More precisely, b1 and b point to the same tree object

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  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 15:59 ` Junio C Hamano
  2009-05-12 16:38   ` Ping Yin
  2009-05-12 16:07 ` Jeff King
  2 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2009-05-12 15:59 UTC (permalink / raw)
  To: Ping Yin; +Cc: git mailing list

Ping Yin <pkufranky@gmail.com> writes:

> 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) )

On "c", you can:

    git read-tree -m -u b
    git commit

I think with newer git you can say

    git reset --merge b
    git commit

instead, to save some typing.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 15:47 ` Ping Yin
@ 2009-05-12 16:04   ` Tomas Carnecky
  2009-05-13 14:36     ` Sitaram Chamarty
  0 siblings, 1 reply; 10+ messages in thread
From: Tomas Carnecky @ 2009-05-12 16:04 UTC (permalink / raw)
  To: Ping Yin; +Cc: git mailing list


On May 12, 2009, at 5:47 PM, Ping Yin wrote:

> On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com>  
> 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) )
>
> More precisely, b1 and b point to the same tree object

git checkout c
git cherry-pick b

tom

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  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 15:59 ` Junio C Hamano
@ 2009-05-12 16:07 ` Jeff King
  2009-05-12 16:43   ` Ping Yin
  2 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2009-05-12 16:07 UTC (permalink / raw)
  To: Ping Yin; +Cc: git mailing list

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'

You would probably want to "git checkout -f" afterwards to update the
working tree with what's in the index.

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 <message`
  git update-ref c $commit

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 15:59 ` Junio C Hamano
@ 2009-05-12 16:38   ` Ping Yin
  0 siblings, 0 replies; 10+ messages in thread
From: Ping Yin @ 2009-05-12 16:38 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git mailing list

On Tue, May 12, 2009 at 11:59 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Ping Yin <pkufranky@gmail.com> writes:
>
>> 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) )
>
> On "c", you can:
>
>    git read-tree -m -u b
>    git commit

is -u necessary?

>
> I think with newer git you can say
>
>    git reset --merge b
>    git commit
>

When the working directory is clean, it seems "reset --hard" and
"reset --merge" behave the same. So after "git reset --merge b",  the
HEAD is moved to b, and i have nothing to commit.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 16:07 ` Jeff King
@ 2009-05-12 16:43   ` Ping Yin
  2009-05-12 16:51     ` Jeff King
  0 siblings, 1 reply; 10+ messages in thread
From: Ping Yin @ 2009-05-12 16:43 UTC (permalink / raw)
  To: Jeff King; +Cc: git mailing list

On Wed, May 13, 2009 at 12:07 AM, Jeff King <peff@peff.net> 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 <message`
>  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?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 16:43   ` Ping Yin
@ 2009-05-12 16:51     ` Jeff King
  2009-05-12 16:59       ` Ping Yin
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff King @ 2009-05-12 16:51 UTC (permalink / raw)
  To: Ping Yin; +Cc: git mailing list

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 16:51     ` Jeff King
@ 2009-05-12 16:59       ` Ping Yin
  0 siblings, 0 replies; 10+ messages in thread
From: Ping Yin @ 2009-05-12 16:59 UTC (permalink / raw)
  To: Jeff King; +Cc: git mailing list

On Wed, May 13, 2009 at 12:51 AM, Jeff King <peff@peff.net> wrote:
> 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.

I don't want to touch the working directory, and -m will keep the stat
cache in the index, so i think "git read-tree -m b" is the best.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to create a new commit with the content of some commit?
  2009-05-12 16:04   ` Tomas Carnecky
@ 2009-05-13 14:36     ` Sitaram Chamarty
  0 siblings, 0 replies; 10+ messages in thread
From: Sitaram Chamarty @ 2009-05-13 14:36 UTC (permalink / raw)
  To: git

On 2009-05-12, Tomas Carnecky <tom@dbservice.com> wrote:
>
> On May 12, 2009, at 5:47 PM, Ping Yin wrote:
>
>> On Tue, May 12, 2009 at 10:35 PM, Ping Yin <pkufranky@gmail.com>  
>> 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) )
>>
>> More precisely, b1 and b point to the same tree object
>
> git checkout c
> git cherry-pick b

I do not think this does what was wanted.  Applying the
change from a->b onto c may not give you "b" unless a==c.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-05-13 14:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2009-05-12 16:59       ` Ping Yin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).