All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
To: mat <matthieu.stigler@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Looks like --amend create commit... don't understand
Date: Wed, 24 Feb 2010 23:01:22 +0100	[thread overview]
Message-ID: <vpqr5oa9tu5.fsf@bauges.imag.fr> (raw)
In-Reply-To: <4B8599C4.1050409@gmail.com> (mat's message of "Wed\, 24 Feb 2010 22\:27\:32 +0100")

mat <matthieu.stigler@gmail.com> writes:

> commits. But when looking on gitk, I see that
> git commit blabla --amend
>
> does create each and every time a new commit,

Yes. In Git, objects (including commits) are fundamentally immutable.
You never modify an object, you create a new one, and usually forget
about the old one.

> I mean: with git log,
> there is only one commit, but on gitk, I see many, with the same name
> but different revision ID....

The revision ID is the sha1sum of the commit content. So, if they have
different contents, they _must_ have different IDs.

What happens is that you start with a history like

A---B <- master

and then try to --amend B. What happens is that you create a new B,
say B', and let the branch you sit on point to this new one. Like:

A---B
 \
  `-B' <- master

Most of the time, B has just become unreachable: no branch contain it,
no tag point to it, ... so you actually see

A---B' <- master

and it very much looks like you just modified B.

Now, if you made B reachable before your commit --amend, like by
pushing it to another repo, letting someone else pull from it, or if B
is already part of another branch, then the situation is different.

For example, if B is already part of a branch, like this:

    .---- temp-branch
    v
A---B---C <- master

If you do a checkout of temp-branch, then commit --amend, you end up
in this situation :

A---B---C <- master
 \
  `-B' <- temp-branch

The solutions:

* If you already published your commit, then don't amend it. Period.

* If you want to rewrite an old commit in a branch, then read about
  "git rebase -i", but make sure you read all the warnings about
  rebase before you do so.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

  reply	other threads:[~2010-02-24 22:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 21:27 Looks like --amend create commit... don't understand mat
2010-02-24 22:01 ` Matthieu Moy [this message]
2010-02-25 20:45   ` mat
2010-02-25 22:25 ` Octavio Alvarez

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=vpqr5oa9tu5.fsf@bauges.imag.fr \
    --to=matthieu.moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=matthieu.stigler@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.