git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Question: behavior when reverting a commit from a shallow clone

From
SSphinx <sphinx9692@gmail.com>
Date
Oct 3, 2026, 08:54 UTC
Message-ID
<CALfz8Qx63qNoSbXq7C7u+KwX4=HCL7=uOUahpXd6j7KvW_c_Eg@mail.gmail.com>
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

Next: Carlisle T. Hamlin
Message 1 of 10 in “Question: behavior when reverting a commit from a shallow clone”
  1. SphinxOct 3, 2026
  2. Carlisle T. HamlinOct 3, 2026
  3. Patrick SteinhardtOct 5, 2026
  4. Carlisle T. HamlinOct 5, 2026
  5. Patrick SteinhardtOct 5, 2026
  6. Matt HunterOct 5, 2026
  7. Junio C HamanoOct 5, 2026
  8. Junio C HamanoOct 6, 2026
  9. SphinxOct 9, 2026
  10. SphinxOct 5, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.