{"thread":{"id":"30353","subject":"Pulling without any local commits deletes stages files without warning.","startedAt":"2012-04-29T00:29:09Z","lastAt":"2012-04-29T04:21:29Z","messageCount":2,"participants":["Jem","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"190241","messageId":"CAHzj05Uy-zofirgnhqK_t+jdD41J8yG5OJk-QCHmQ+OZLWfMqw@mail.gmail.com","threadId":"30353","inReplyTo":null,"subject":"Pulling without any local commits deletes stages files without warning.","fromName":"Jem","fromEmail":"jem.mawson@gmail.com","sentAt":"2012-04-29T00:29:09Z","receivedAt":"2012-04-29T00:29:09Z","isPatch":false,"sender":{"key":"jem.mawson@gmail.com","avatar":null},"body":"Hi\n\nPulling without any local commits deletes staged files without\nwarning. Is this intended behaviour? Log:\n\njem@jem-usb:~/projects$ git --version\ngit version 1.7.9.5\njem@jem-usb:~/projects$ uname -a\nLinux jem-usb 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09\nUTC 2012 i686 i686 i386 GNU/Linux\njem@jem-usb:~/projects$ mkdir x\njem@jem-usb:~/projects$ cd x\njem@jem-usb:~/projects/x$ git init\nInitialized empty Git repository in /home/jem/projects/x/.git/\njem@jem-usb:~/projects/x$ echo \"hi\" > hello.world\njem@jem-usb:~/projects/x$ git add hello.world\njem@jem-usb:~/projects/x$ git status\n# On branch master\n#\n# Initial commit\n#\n# Changes to be committed:\n#   (use \"git rm --cached <file>...\" to unstage)\n#\n#       new file:   hello.world\n#\njem@jem-usb:~/projects/x$ ls -asl\ntotal 24\n4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:56 .\n4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:56 ..\n4 drwxrwxr-x 7 jem jem 4096 Apr 28 20:56 .git\n12 -rw-rw-r-- 1 jem jem    3 Apr 28 20:56 hello.world\njem@jem-usb:~/projects/x$ git remote add origin git@github.com:Synesso/memx.git\njem@jem-usb:~/projects/x$ git reflog\nfatal: bad default revision 'HEAD'\njem@jem-usb:~/projects/x$ git pull origin master\nremote: Counting objects: 7, done.\nremote: Compressing objects: 100% (5/5), done.\nremote: Total 7 (delta 0), reused 3 (delta 0)\nUnpacking objects: 100% (7/7), done.\nFrom github.com:Synesso/memx\n* branch            master     -> FETCH_HEAD\njem@jem-usb:~/projects/x$ ls -asl\ntotal 36\n4 drwxrwxr-x 3 jem jem 4096 Apr 28 20:53 .\n4 drwxr-xr-x 8 jem jem 4096 Apr 28 20:52 ..\n4 drwxrwxr-x 8 jem jem 4096 Apr 28 20:53 .git\n12 -rw-rw-r-- 1 jem jem   59 Apr 28 20:53 .gitignore\n12 -rw-rw-r-- 1 jem jem    9 Apr 28 20:53 README.md\njem@jem-usb:~/projects/x$ git reflog\nc80135d HEAD@{0}: initial pull\n"},{"id":"190242","messageId":"xmqqk40z88xi.fsf@junio.mtv.corp.google.com","threadId":"30353","inReplyTo":"CAHzj05Uy-zofirgnhqK_t+jdD41J8yG5OJk-QCHmQ+OZLWfMqw@mail.gmail.com","subject":"Re: Pulling without any local commits deletes stages files without warning.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-04-29T04:21:29Z","receivedAt":"2012-04-29T04:21:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jem <jem.mawson@gmail.com> writes:\n\n> Pulling without any local commits deletes staged files without\n> warning. Is this intended behaviour?\n\nIt is an unanticipated corner case interfering our attempt to be too\nnice that backfired.\n\nFor a long time, having no history and asking to pull was forbidden,\nbecause \"git pull\" is is about combining two (or more) histories\ntogether and pulling when you have no history is a nonsense --- you only\nhave one history (the history from the other side) and there is nothing\nto combine.\n\nLater we tried to be nicer, as some new users triggered an error when\ndoing \"git init\" in an empty directory followed by \"git pull\", by\nredefining \"merge\" into no history to mean resetting to the other\nhistory.\n\nThis solved \"git init && git pull\", but we did not anticipate anybody\nwould do a \"git init && git add && git pull\" sequence, to which there is\nno sane outcome other than just erroring out.\n\nA patch to give that only sane outcome may look like this.\n\n git-pull.sh |    3 +++\n 1 file changed, 3 insertions(+)\n\ndiff --git a/git-pull.sh b/git-pull.sh\nindex 2a10047..da102d0 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -261,6 +261,9 @@ esac\n \n if test -z \"$orig_head\"\n then\n+\ttest $(git ls-files | wc -l) = 0 ||\n+\tdie \"$(gettext \"Uncommitted changes in the index\")\"\n+\n \tgit update-ref -m \"initial pull\" HEAD $merge_head \"$curr_head\" &&\n \tgit read-tree -m -u HEAD || exit 1\n \texit\n"}]}