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

Re: Possible regression: overwriting untracked files in a fresh repo

From
Jeff King <peff@peff.net>
Date
Aug 25, 2009, 01:47 UTC
Message-ID
<20090825014738.GA7655@coredump.intra.peff.net>
In-Reply-To
<20090825013601.GA3515@coredump.intra.peff.net>
On Mon, Aug 24, 2009 at 09:36:01PM -0400, Jeff King wrote:
Show 7 quoted lines
> I don't think this is the right thing to do. We have _no_ current
> branch, which means that everything in the working tree can be
> considered untracked (and therefore precious). So I think the right
> thing to do is barf and say "this untracked file would be overwritten".
> The user can sort it out as appropriate, either deleting files that are
> in the way, or using "-f" themselves (after they make the decision that
> what they have can be overwritten).

Actually, let me clarify that a bit. If we have no branch _and_ we have no index, then everything is untracked. If we do have an index, then we do a two-way merge from the HEAD. So if we have no branch in that case, it makes sense to me to treat every element of the index as an addition, meaning that anything in the new tree that is different should be a conflict.

And that is what my patch does: it pretends that the HEAD is the empty tree, which should produce sane output in both cases:

  $ echo content >file
  $ git checkout -b foo origin ;# origin has 'file' in it
  error: Untracked working tree file 'file' would be overwritten by merge.
  $ git add file
  $ git checkout -b foo origin
  error: Entry 'file' would be overwritten by merge. Cannot merge.
and it even handles the matching-index case when the merge is a no-op:
  $ git show origin:file >file ;# match contents
  $ git checkout -b foo origin
  error: Untracked working tree file 'file' would be overwritten by merge.
  $ git add file
  $ git checkout -b foo origin
  Switched to a new branch 'foo'
-Peff
Previous: Jeff KingNext: Junio C Hamano
Message 6 of 9 in “Possible regression: overwriting untracked files in a fresh repo”
  1. Johannes SchindelinAug 24, 2009
  2. Jeff KingAug 24, 2009
  3. Junio C HamanoAug 24, 2009
  4. Junio C HamanoAug 24, 2009
  5. Jeff KingAug 25, 2009
  6. Jeff KingAug 25, 2009
  7. Junio C HamanoAug 25, 2009
  8. Jeff KingAug 25, 2009
  9. Johannes SchindelinAug 25, 2009

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.