All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Paul Richards <paul.richards@gmail.com>
Cc: git@vger.kernel.org, Christian Couder <chriscool@tuxfamily.org>
Subject: Re: Alter parent ID of existing commit object
Date: Mon, 26 Apr 2010 05:38:02 -0500	[thread overview]
Message-ID: <20100426103637.GA8896@progeny.tock> (raw)
In-Reply-To: <n2xa1138db31004260313jcd22b2ebw403ca2bd547e784b@mail.gmail.com>

Hi Paul,

Paul Richards wrote:

> Is it possible to edit an old commit object and only alter the ID of
> the parent commit but otherwise leave all the other information intact
> (tree, message, authors, date, etc).
> 
> I'd expect such a command to return the new hash of the modified commit.

The standard answer to this question is to say “use grafts and
filter-branch”.  The git-filter-branch(1) man page explains this
approach.  It is very powerful, but sometimes I do not want to have
that much power.

So I will tell a secret: in the scenarios when I wanted something like
this (actually, what I have occasionally wanted is to transform a
single-parent commit into a merge), I did something like the following:

  $ git cat-file commit $rev
  tree dcd2cc4b76f8756423f5c1ab7d2c62d458a8b15f
  parent 5f1e6d9ce35e212708f9adc55e6b9a7e0d296df4
  author Will Palmer <wmpalmer@gmail.com> 1272275407 -0500
  committer Jonathan Nieder <jrnieder@gmail.com> 1272275443 -0500
  
  pretty: Respect --abbrev option
  
  Prior to this, the output of git log -1 --format=%h was always 7
  characters long, without regard to whether --abbrev had been passed.
  
  Signed-off-by: Will Palmer <wmpalmer@gmail.com>
  Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
  $ git cat-file commit $rev >tmp
  $ sed -i -e "s/parent .*/parent $(git rev-parse othercommit)/" tmp
  $ git hash-object -t commit -w tmp
  ca55c560685284ac6d121939b2cd881f426e7074

Easy.  Still, I would be happy to see this packaged in a command, so I
could recommend it in combination with ‘git replace’ to people who are
scared of sed.

Thanks for bringing it up.
Jonathan

  reply	other threads:[~2010-04-26 10:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-26 10:13 Alter parent ID of existing commit object Paul Richards
2010-04-26 10:38 ` Jonathan Nieder [this message]
2010-04-26 11:02   ` Paul Richards
2010-04-26 23:34   ` Jakub Narebski

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=20100426103637.GA8896@progeny.tock \
    --to=jrnieder@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=paul.richards@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.