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

Re: Pulling without any local commits deletes stages files without warning.

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 29, 2012, 04:21 UTC
Message-ID
<xmqqk40z88xi.fsf@junio.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
Previous: Jem
Message 2 of 2 in “Pulling without any local commits deletes stages files without warning.”
  1. JemApr 29, 2012
  2. Junio C HamanoApr 29, 2012

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.