Git development
 help / color / mirror / Atom feed
* Question: behavior when reverting a commit from a shallow clone
@ 2026-10-03  8:54 Sphinx
  2026-10-03 19:41 ` Carlisle T. Hamlin
  2026-10-05  6:57 ` Patrick Steinhardt
  0 siblings, 2 replies; 10+ messages in thread
From: Sphinx @ 2026-10-03  8:54 UTC (permalink / raw)
  To: git

Hi Git maintainers,

I have been investigating Git's behavior in a particular destructive
scenario and wanted to verify my understanding with the maintainers.

Consider the following repository history:

A -> B

where A contains the repository's files and B is the current HEAD.

The repository is then cloned with:

git clone --depth=1 <repository>

so only B is available locally and its parent A is not present in the
shallow clone.

If an operation is then performed to restore/revert B, I was looking
into the behavior when the resulting working tree/index becomes empty
— effectively causing all tracked files to be removed.

I have gone through the Git documentation and experimented with the
relevant Git commands, including the behavior of shallow repositories,
branch deletion, working-tree changes, resets, restores, and other
destructive operations. Based on my investigation, I have not been
able to find evidence that Git provides a warning or confirmation
specifically when an operation results in all tracked files being
removed or produces an empty tree.

Before drawing any conclusions, I wanted to verify this with the Git developers.

Is the following understanding correct?

An empty tree is a valid Git state, so Git does not generally consider
transitioning from a non-empty tree to an empty tree inherently
erroneous.

Git does not have a general safeguard that warns when an operation
will delete all tracked files.

If there are existing safeguards, warnings, configuration options, or
historical discussions that I may have missed, I would appreciate any
pointers.

The reason I am asking is that I am trying to establish precisely
where Git's safety boundary is in this scenario specifically, whether
Git itself is expected to warn about the resulting empty tree, or
whether detecting an unexpectedly destructive tree change is
considered the responsibility of the tooling performing the operation.

Thanks,
A fellow git user

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-10-09 17:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-10-09 17:34     ` Sphinx

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox