git merge, .gitignore, and silently overwriting untracked files

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joshua Jensen
Date: Monday, August 16, 2010 - 10:21 pm

Git silently overwrote an important untracked file for me today.  I 
have come up with the following transcript to reproduce the issue.

In a nutshell, if an untracked file is in .gitignore, a merge from a 
branch where the file was added will OVERWRITE the untracked file 
without warning.

This doesn't seem right.

What do others think?

Josh

-------------------------------

/s/testgitoverwrite
$ mkdir aaa

/s/testgitoverwrite
$ cd aaa

/s/testgitoverwrite/aaa
$ echo abc > abc.txt

/s/testgitoverwrite/aaa
$ ls -l
total 1
-rw-r--r--    1 Joshua   Administ        4 Aug 16 23:10 abc.txt

/s/testgitoverwrite/aaa
$ git init
Initialized empty Git repository in s:/testgitoverwrite/aaa/.git/

/s/testgitoverwrite/aaa (master)
$ git add abc.txt

/s/testgitoverwrite/aaa (master)
$ git commit -m "Added abc.txt"
[master (root-commit) 0e8bffb] Added abc.txt
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 abc.txt

/s/testgitoverwrite/aaa (master)
$ cd ..

/s/testgitoverwrite
$ git clone aaa bbb
Cloning into bbb...
done.

/s/testgitoverwrite
$ cd bbb

/s/testgitoverwrite/bbb (master)
$ ls -l
total 1
-rw-r--r--    1 Joshua   Administ        4 Aug 16 23:10 abc.txt

/s/testgitoverwrite/bbb (master)
$ echo "Important stuff" > important.txt

/s/testgitoverwrite/bbb (master)
$ git add important.txt

/s/testgitoverwrite/bbb (master)
$ git commit -m "This file is SO important"
[master 2fe9ab6] This file is SO important
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 important.txt

/s/testgitoverwrite/bbb (master)
$ cd ..

/s/testgitoverwrite
$ cd aaa

/s/testgitoverwrite/aaa (master)
$ echo "Local testing copy of important.txt" > important.txt

/s/testgitoverwrite/aaa (master)
$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       important.txt
nothing added to commit but untracked files present (use "git add" to track)

/s/testgitoverwrite/aaa (master)
$ git pull ../bbb
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
 From ../bbb
  * branch            HEAD       -> FETCH_HEAD
Updating 0e8bffb..2fe9ab6
error: Untracked working tree file 'important.txt' would be overwritten 
by merge.  Aborting

/s/testgitoverwrite/aaa (master)
$ git pull --rebase ../bbb
 From ../bbb
  * branch            HEAD       -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
error: Untracked working tree file 'important.txt' would be overwritten 
by merge.
could not detach HEAD

/s/testgitoverwrite/aaa (master)
$ echo important.txt > .gitignore

/s/testgitoverwrite/aaa (master)
$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .gitignore
nothing added to commit but untracked files present (use "git add" to track)

/s/testgitoverwrite/aaa (master)
$ cat important.txt
Local testing copy of important.txt

/s/testgitoverwrite/aaa (master)
$ git pull ../bbb
 From ../bbb
  * branch            HEAD       -> FETCH_HEAD
Updating 0e8bffb..2fe9ab6
Fast-forward
  important.txt |    1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
  create mode 100644 important.txt

/s/testgitoverwrite/aaa (master)
$ cat important.txt
Important stuff


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
git merge, .gitignore, and silently overwriting untracked ..., Joshua Jensen, (Mon Aug 16, 10:21 pm)
[PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Wed Aug 18, 4:39 pm)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Fri Aug 20, 11:48 am)
[PATCH v2] optionally disable overwriting of ignored files, Clemens Buchacher, (Fri Aug 20, 11:48 pm)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Sat Aug 21, 1:05 am)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Sat Aug 21, 6:23 am)
Re: [PATCH] optionally disable overwriting of ignored files, Junio C Hamano, (Sun Aug 22, 12:25 am)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Sun Aug 22, 1:20 am)
Re: [PATCH] optionally disable overwriting of ignored files, Holger Hellmuth, (Mon Aug 23, 6:56 am)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Mon Aug 23, 8:11 am)
Re: [PATCH] optionally disable overwriting of ignored files, Clemens Buchacher, (Tue Aug 24, 12:28 am)
[PATCH 0/5] do not overwrite untracked files in leading path, Clemens Buchacher, (Sat Oct 9, 6:52 am)
[PATCH 1/5] t7607: use test_commit and test_must_fail, Clemens Buchacher, (Sat Oct 9, 6:52 am)
[PATCH 2/5] t7607: add leading-path tests, Clemens Buchacher, (Sat Oct 9, 6:52 am)
[PATCH 3/5] add function check_ok_to_remove(), Clemens Buchacher, (Sat Oct 9, 6:52 am)
[PATCH 4/5] lstat_cache: optionally return match_len, Clemens Buchacher, (Sat Oct 9, 6:52 am)
[PATCH 5/5] do not overwrite files in leading path, Clemens Buchacher, (Sat Oct 9, 6:53 am)
Re: [PATCH 2/5] t7607: add leading-path tests, Johannes Sixt, (Sat Oct 9, 12:14 pm)
Re: [PATCH 1/5] t7607: use test_commit and test_must_fail, Jonathan Nieder, (Sat Oct 9, 11:35 pm)
[PATCH 1/5 v2] t7607: use test-lib functions and check MER ..., Clemens Buchacher, (Sun Oct 10, 1:35 am)
[PATCH 2/5 v2] t7607: add leading-path tests, Clemens Buchacher, (Sun Oct 10, 1:38 am)
Re: [PATCH 3/5] add function check_ok_to_remove(), Junio C Hamano, (Wed Oct 13, 2:43 pm)
Re: [PATCH 5/5] do not overwrite files in leading path, Junio C Hamano, (Wed Oct 13, 2:57 pm)
Re: [PATCH 5/5] do not overwrite files in leading path, Clemens Buchacher, (Wed Oct 13, 3:34 pm)
Re: [PATCH 5/5] do not overwrite files in leading path, Clemens Buchacher, (Thu Oct 14, 11:48 pm)
Re: [PATCH 5/5] do not overwrite files in leading path, Junio C Hamano, (Fri Oct 15, 11:47 am)