Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Sphinx <sphinx9692@gmail.com>,  git@vger.kernel.org
Subject: Re: Question: behavior when reverting a commit from a shallow clone
Date: Tue, 06 Oct 2026 08:54:08 -0700	[thread overview]
Message-ID: <xmqqbj96g6zj.fsf@gitster.g> (raw)
In-Reply-To: <asNKZpxiuFhVkVQd@pks.im> (Patrick Steinhardt's message of "Mon, 5 Oct 2026 08:57:42 +0200")

Patrick Steinhardt <ps@pks.im> writes:

> Yeah, this can indeed be surprising behaviour. The reason for it is that
> in a shallow clone, we rewrite the boundary commit (so in your case B)
> so that it doesn't have any parents anymore. It thus looks like just
> another root commit that has added all files in a single go. And the
> consequence of that is that reverting it will then delete everything.
>
> Now arguably, Git could be improved here. We just recently had a similar
> discussion around maybe forbidding to "git commit --amend" such a
> shallow commit. Your scenario is a second one where Git should probably
> at least warn about what's happening.
>
> Arguably we should even completely refuse editing such a shallow commit
> by default. I would guess that in 99% of all the cases where a user does
> it it's unintended. And for the 1% where it's actually intended we could
> give users a way to override this safeguard.

Yeah, I think that line of thinking is going in the right direction.

It is not surprising that these non-core features (read: as opposed
to really core features that were already considered mature even
back in Git 1.5.3) that had many years to mature still has rough
edges even today around corners that practicaly nobody has touched,
and we should not be afraid to round them further.

> I wouldn't warn about an empty tree in general. But editing a commit
> that is a shallow boundary is something that I'd agree Git should warn
> about, if not even refuse by default.

Yes.  Committing an empty tree, whether at the beginning of a
project or in the middle of a project after you fed up with too many
bugs in your early attempts and want to start clean, is a perfectly
normal, if wasteful, thing to do.

Thanks.

  parent reply	other threads:[~2026-10-06 15:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-03  8:54 Question: behavior when reverting a commit from a shallow clone Sphinx
2026-10-03 19:41 ` Carlisle T. Hamlin
2026-10-05  6:57   ` Patrick Steinhardt
2026-10-05 18:10     ` Carlisle T. Hamlin
2026-10-05  6:57 ` Patrick Steinhardt
2026-10-05 10:41   ` Matt Hunter
2026-10-05 16:38     ` Junio C Hamano
     [not found]       ` <CALfz8QzymKxvzYGWLwdtzERDm1apa8ebZEVyLne18hpTaB=D0g@mail.gmail.com>
2026-10-05 17:35         ` Sphinx
2026-10-06 15:54   ` Junio C Hamano [this message]
2026-10-09 17:34     ` Sphinx

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=xmqqbj96g6zj.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=sphinx9692@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