# Pulling without any local commits deletes stages files without warning.

2 messages from 2012-04-29 to 2012-04-29. Participants: Jem, Junio C Hamano.
Thread: https://gitlist.dev/t/30353

## Jem, 2012-04-29 00:29

Subject: Pulling without any local commits deletes stages files without warning.
Message-ID: <CAHzj05Uy-zofirgnhqK_t+jdD41J8yG5OJk-QCHmQ+OZLWfMqw@mail.gmail.com>
URL: https://gitlist.dev/e/CAHzj05Uy-zofirgnhqK_t%2BjdD41J8yG5OJk-QCHmQ%2BOZLWfMqw%40mail.gmail.com

```
Hi

Pulling without any local commits deletes staged files without
warning. Is this intended behaviour? Log:

jem@jem-usb:~/projects$ git --version
git version 1.7.9.5
jem@jem-usb:~/projects$ uname -a
Linux jem-usb 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09
UTC 2012 i686 i686 i386 GNU/Linux
jem@jem-usb:~/projects$ mkdir x
jem@jem-usb:~/projects$ cd x
jem@jem-usb:~/projects/x$ git init
Initialized empty Git repository in /home/jem/projects/x/.git/
jem@jem-usb:~/projects/x$ echo "hi" > hello.world
jem@jem-usb:~/projects/x$ git add hello.world
jem@jem-usb:~/projects/x$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   hello.world
#
jem@jem-usb:~/projects/x$ ls -asl
total 24
4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:56 .
4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:56 ..
4 drwxrwxr-x 7 jem jem 4096 Apr 28 20:56 .git
12 -rw-rw-r-- 1 jem jem    3 Apr 28 20:56 hello.world
jem@jem-usb:~/projects/x$ git remote add origin git@github.com:Synesso/memx.git
jem@jem-usb:~/projects/x$ git reflog
fatal: bad default revision 'HEAD'
jem@jem-usb:~/projects/x$ git pull origin master
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 7 (delta 0), reused 3 (delta 0)
Unpacking objects: 100% (7/7), done.
From github.com:Synesso/memx
* branch            master     -> FETCH_HEAD
jem@jem-usb:~/projects/x$ ls -asl
total 36
4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:53 .
4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:52 ..
4 drwxrwxr-x 8 jem jem 4096 Apr 28 20:53 .git
12 -rw-rw-r-- 1 jem jem   59 Apr 28 20:53 .gitignore
12 -rw-rw-r-- 1 jem jem    9 Apr 28 20:53 README.md
jem@jem-usb:~/projects/x$ git reflog
c80135d HEAD@{0}: initial pull

```

## Junio C Hamano, 2012-04-29 04:21

Subject: Re: Pulling without any local commits deletes stages files without warning.
Message-ID: <xmqqk40z88xi.fsf@junio.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqk40z88xi.fsf%40junio.mtv.corp.google.com
In-Reply-To: <CAHzj05Uy-zofirgnhqK_t+jdD41J8yG5OJk-QCHmQ+OZLWfMqw@mail.gmail.com>

```
Jem <jem.mawson@gmail.com> writes:

> Pulling without any local commits deletes staged files without
> warning. Is this intended behaviour?

It is an unanticipated corner case interfering our attempt to be too
nice that backfired.

For a long time, having no history and asking to pull was forbidden,
because "git pull" is is about combining two (or more) histories
together and pulling when you have no history is a nonsense --- you only
have one history (the history from the other side) and there is nothing
to combine.

Later we tried to be nicer, as some new users triggered an error when
doing "git init" in an empty directory followed by "git pull", by
redefining "merge" into no history to mean resetting to the other
history.

This solved "git init && git pull", but we did not anticipate anybody
would do a "git init && git add && git pull" sequence, to which there is
no sane outcome other than just erroring out.

A patch to give that only sane outcome may look like this.

 git-pull.sh |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/git-pull.sh b/git-pull.sh
index 2a10047..da102d0 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -261,6 +261,9 @@ esac
 
 if test -z "$orig_head"
 then
+	test $(git ls-files | wc -l) = 0 ||
+	die "$(gettext "Uncommitted changes in the index")"
+
 	git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
 	git read-tree -m -u HEAD || exit 1
 	exit

```
