threads / discuss / 43108

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

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

## tl;dr

8 messages between Nov 11, 2006 and Nov 11, 2006.

replies: 7people: 5as markdown or json

Nguyen Thai Ngoc Duy· Nov 11, 2006, 11:08 UTC · lore

check if a commit is ascendent of a specific commit

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· Nov 11, 2006, 11:15 UTC · re: Nguyen Thai Ngoc Duy · lore
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· Nov 11, 2006, 11:19 UTC · re: Nguyen Thai Ngoc Duy · lore
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
Junio C Hamano· Nov 11, 2006, 18:43 UTC · re: Nguyen Thai Ngoc Duy · lore
"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· Nov 11, 2006, 19:23 UTC · re: Junio C Hamano · lore
On Sat, Nov 11, 2006 at 10:43:47AM -0800, Junio C Hamano wrote:
Show 8 quoted lines
> "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· Nov 11, 2006, 20:12 UTC · re: Tom Prince · lore
Tom Prince <tom.prince@ualberta.net> writes:
Show 11 quoted lines
> 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 ;-).
Jakub Narebski· Nov 11, 2006, 11:56 UTC · lore
Dnia sobota 11. listopada 2006 12:31, Nguyen Thai Ngoc Duy napisał:
Show 8 quoted lines
> 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· Nov 11, 2006, 12:12 UTC · re: Jakub Narebski · lore
On 2006-11-11 12:56:19 +0100, Jakub Narebski wrote:
Show 14 quoted lines
> 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

← back to recent threads