# Re: check if a commit is ascendent of a specific commit

8 messages from 2006-11-11 to 2006-11-11. Participants: Nguyen Thai Ngoc Duy, Junio C Hamano, Karl Hasselström, Jakub Narebski, Tom Prince.
Thread: https://gitlist.dev/t/43108

## Nguyen Thai Ngoc Duy, 2006-11-11 11:08

Subject: check if a commit is ascendent of a specific commit
Message-ID: <fcaeb9bf0611110308l577d70bfo5046d7d7eb09ac58@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0611110308l577d70bfo5046d7d7eb09ac58%40mail.gmail.com

```
Hi,
I want to create "git-amend-commit" to be able to amend commits before
HEAD. So I need to check whether the commit I'm going to amend is
ascendent of HEAD. Is there any way to check that?
-- 

```

## Jakub Narebski, 2006-11-11 11:15

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <ej4ba6$oqt$1@sea.gmane.org>
URL: https://gitlist.dev/e/ej4ba6%24oqt%241%40sea.gmane.org
In-Reply-To: <fcaeb9bf0611110308l577d70bfo5046d7d7eb09ac58@mail.gmail.com>

```
Nguyen Thai Ngoc Duy wrote:

> Hi,
> I want to create "git-amend-commit" to be able to amend commits before
> HEAD. So I need to check whether the commit I'm going to amend is
> ascendent of HEAD. Is there any way to check that?

You can only amend topmost commit in any branch. Anything else would
be rewriting history, starting from amended commit upwards in lineage
(parentage).

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git


```

## Nguyen Thai Ngoc Duy, 2006-11-11 11:19

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <fcaeb9bf0611110319i680a3805l5f6e6059644642ea@mail.gmail.com>
URL: https://gitlist.dev/e/fcaeb9bf0611110319i680a3805l5f6e6059644642ea%40mail.gmail.com
In-Reply-To: <fcaeb9bf0611110308l577d70bfo5046d7d7eb09ac58@mail.gmail.com>

```
On 11/11/06, Nguyen Thai Ngoc Duy <pclouds@gmail.com> wrote:
> Hi,
> I want to create "git-amend-commit" to be able to amend commits before
> HEAD. So I need to check whether the commit I'm going to amend is
> ascendent of HEAD. Is there any way to check that?

Forget it. It's git-merge-base. Sorry for the noise

-- 

```

## Jakub Narebski, 2006-11-11 11:56

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <200611111256.20157.jnareb@gmail.com>
URL: https://gitlist.dev/e/200611111256.20157.jnareb%40gmail.com
In-Reply-To: <fcaeb9bf0611110331q53522c50sda399d4a7916636d@mail.gmail.com>

```
Dnia sobota 11. listopada 2006 12:31, Nguyen Thai Ngoc Duy napisał:
> On 11/11/06, Jakub Narebski <jnareb@gmail.com> wrote:
>> You can only amend topmost commit in any branch. Anything else would
>> be rewriting history, starting from amended commit upwards in lineage
>> (parentage).
> 
> Yes. That's what I want. I am tempted to edit older commits just
> because I forgot to add some entries to .gitignore that I should have
> added sooner :-)

In pure git you would have to create new branch at the commit you want
to amend, amend the commit (in this branch), and rebase (or cherry-pick
if you need to edit other commits too) the rest, then rename branch.
Or if you don't want ot loose reflog, tag/branch current branch, then reset
(rewind) current branch to the commit you want to amend, then cherry-pick.

Or you can use cg-admin-rewritehist tool from Cogito.

See: http://git.or.cz/gitwiki/GitTips
-- 
Jakub Narebski

```

## Karl Hasselström, 2006-11-11 12:12

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <20061111121259.GB11224@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20061111121259.GB11224%40diana.vm.bytemark.co.uk
In-Reply-To: <200611111256.20157.jnareb@gmail.com>

```
On 2006-11-11 12:56:19 +0100, Jakub Narebski wrote:

> Dnia sobota 11. listopada 2006 12:31, Nguyen Thai Ngoc Duy napisa??:
>
> > Yes. That's what I want. I am tempted to edit older commits just
> > because I forgot to add some entries to .gitignore that I should
> > have added sooner :-)
>
> In pure git you would have to create new branch at the commit you
> want to amend, amend the commit (in this branch), and rebase (or
> cherry-pick if you need to edit other commits too) the rest, then
> rename branch. Or if you don't want ot loose reflog, tag/branch
> current branch, then reset (rewind) current branch to the commit you
> want to amend, then cherry-pick.
>
> Or you can use cg-admin-rewritehist tool from Cogito.

In case the history you want to edit is linear (that is, merge-free),
StGIT is an excellent tool. It is very easy to go back to a previous
commit (stg pop), amend it (stg refresh), and replay the following
commits on top of the amended commit (stg push).

-- 
Karl Hasselström, kha@treskal.com

```

## Junio C Hamano, 2006-11-11 18:43

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <7virhlken0.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7virhlken0.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <fcaeb9bf0611110308l577d70bfo5046d7d7eb09ac58@mail.gmail.com>

```
"Nguyen Thai Ngoc Duy" <pclouds@gmail.com> writes:

> Hi,
> I want to create "git-amend-commit" to be able to amend commits before
> HEAD. So I need to check whether the commit I'm going to amend is
> ascendent of HEAD. Is there any way to check that?

Ascendant is a word from astorology -- you mean ancestor ;-).

"git-merge-base A B === A" when A is an ancestor of B.

Provided if the history between A and B is linear, and you do
not have trouble making your co-workers adjusting to your
history change after A (including the cases where you do not
have any co-workers or you have not made history between A and B
public), you could do one of these three things:

 - use "stg uncommit" until you pop A, make a change there and
   "stg refresh", and then "stg push" everything back.

 - "git format-patch A && git reset --hard A", edit the patches
   and then "git am" them.

 - "git tag -f Anchor && git reset --hard A", edit and "git
   commit --amend".  Look at "git show-branch Anchor HEAD", and
   repeatedly "git cherry-pick Anchor~$n" from older to newer
   from Anchor, and then "git tag -d Anchor".






```

## Tom Prince, 2006-11-11 19:23

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <20061111192321.GJ4862@socrates.priv>
URL: https://gitlist.dev/e/20061111192321.GJ4862%40socrates.priv
In-Reply-To: <7virhlken0.fsf@assigned-by-dhcp.cox.net>

```
On Sat, Nov 11, 2006 at 10:43:47AM -0800, Junio C Hamano wrote:
> "Nguyen Thai Ngoc Duy" <pclouds@gmail.com> writes:
> 
> > Hi,
> > I want to create "git-amend-commit" to be able to amend commits before
> > HEAD. So I need to check whether the commit I'm going to amend is
> > ascendent of HEAD. Is there any way to check that?
> 
> Ascendant is a word from astorology -- you mean ancestor ;-).


```

## Junio C Hamano, 2006-11-11 20:12

Subject: Re: check if a commit is ascendent of a specific commit
Message-ID: <7v64dlkait.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64dlkait.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20061111192321.GJ4862@socrates.priv>

```
Tom Prince <tom.prince@ualberta.net> writes:

> On Sat, Nov 11, 2006 at 10:43:47AM -0800, Junio C Hamano wrote:
>> "Nguyen Thai Ngoc Duy" <pclouds@gmail.com> writes:
>> 
>> > Hi,
>> > I want to create "git-amend-commit" to be able to amend commits before
>> > HEAD. So I need to check whether the commit I'm going to amend is
>> > ascendent of HEAD. Is there any way to check that?
>> 
>> Ascendant is a word from astorology -- you mean ancestor ;-).
>
> Or antecedent.

Sorry, there is no "or" here -- check our documentation ;-).

```
