From: Johannes Sixt <j.sixt@viscovery.net>
To: vinassa vinassa <vinassa.vinassa@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: git behaviour question regarding SHA-1 and commits
Date: Mon, 14 Nov 2011 08:39:59 +0100 [thread overview]
Message-ID: <4EC0C5CF.3010708@viscovery.net> (raw)
In-Reply-To: <CAJuRt+r9BjYcead6hgzdUT0Bisz1D48cegqkoJ0S537VMYBy_g@mail.gmail.com>
Am 11/13/2011 18:04, schrieb vinassa vinassa:
> I am wondering about how git behaves currently, if I kinda win the
> lottery of the universe, and happen to create a commit with a SHA-1
> that is already the SHA-1 of another commit in the previous history.
> However improbable.
>
> Would that be detected, so that I could just add a newline, and then
> commit with a different resulting SHA-1,
> would I just lose one of those commits (hopefully the new one), would
> I end up with a corrupted repository?
I *think* the following would happen:
1. Git detects that the (commit) object that it is about to generate
already exists, and does not write a new one.
2. Then the branch's ref is updated to the SHA-1. Since the original
commit is somewhere back in history, this is effectively like 'git reset
--soft that-commit'.
3. At your next 'git diff --cached', you notice unexpected differences
between the index and the branch head. You will wonder what happened.
("Who typed 'git reset --soft that-commit' while I was looking the other
way??")
4. To recover, you just 'git reset --soft @{1}' to revert to the state
before the commit attempt, and commit again. Your commit message from the
first attempt will be lost unless you have used -C or -F for your commit.
At any rate, you can reuse the exact same commit message for this second
commit attempt, because by now time will have advanced by at least one
second, which gives you a different commit timestamp and, hence, a
different commit object.
-- Hannes
prev parent reply other threads:[~2011-11-14 7:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-13 17:04 git behaviour question regarding SHA-1 and commits vinassa vinassa
2011-11-13 17:41 ` Ævar Arnfjörð Bjarmason
2011-11-14 3:29 ` Junio C Hamano
2011-11-14 11:48 ` Jeff King
2011-11-13 18:27 ` Jonathan Nieder
2011-11-13 22:14 ` vinassa vinassa
2011-11-14 11:32 ` Jeff King
2011-11-14 12:48 ` Victor Engmark
2011-11-14 13:04 ` Jeff King
2011-11-13 22:14 ` Dmitry Potapov
2011-11-14 7:39 ` Johannes Sixt [this message]
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=4EC0C5CF.3010708@viscovery.net \
--to=j.sixt@viscovery.net \
--cc=git@vger.kernel.org \
--cc=vinassa.vinassa@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 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 NNTP newsgroup(s).