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

Bogus error: Untracked working tree file '....' would be overwritten by merge. Aborting

From
Ddemerphq <demerphq@gmail.com>
Date
Nov 16, 2010, 10:26 UTC
Message-ID
<AANLkTinv7XsXNR2MMbaGAUo2=WgL6SEWkuzwGU_7YVn0@mail.gmail.com>

The error in the subject line is generated if one has a git repo checked out to a commit that adds a new file and one does something like:

git reset HEAD^
and then a merge operation that involves going forward onto or past HEAD.

Why is this error generated when the file is *exactly* the same as the file that would overwrite it?

Obviously it makes sense to throw this error when data would be lost, but when they are identical what is the point?

In my experience when this happens they are almost always identical, and that this is one of the most common sources of frustration and in my shop a real source of confusion for my colleagues.

I think fixing it to detect they are identical and ignore them when they are would really improve things for the uninitiated.

The following demonstrates the problem:
$ mkdir exp
$ cd exp
$ git init
Initialized empty Git repository in /home/demerphq/exp/.git/
$ echo woohoo > t.txt
$ git add t.txt
$ git commit -m'add t.txt'
[master (root-commit) dbe3cec] add t.txt
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 t.txt
$ echo boohoo > b.txt
$ git add b.txt
$ git commit -m'add b.txt'
[master 15a72ea] add b.txt
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 b.txt
$ git checkout -b other
Switched to a new branch 'other'
$ git reset HEAD^
$ git merge master
Updating dbe3cec..a61413d
error: Untracked working tree file 'b.txt' would be overwritten by merge.
Are there any reasons why this cant be changed?

Cheers, yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"
Next: demerphq
Message 1 of 8 in “Bogus error: Untracked working tree file '....' would be overwritten by merge. Aborting”
  1. demerphqNov 16, 2010
  2. demerphqNov 16, 2010
  3. Nguyen Thai Ngoc DuyNov 16, 2010
  4. Nguyen Thai Ngoc DuyNov 16, 2010
  5. demerphqNov 17, 2010
  6. Ævar Arnfjörð BjarmasonNov 17, 2010
  7. Matthieu MoyNov 17, 2010
  8. Nguyen Thai Ngoc DuyNov 17, 2010

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.