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

Re: Why git silently replaces untracked files?

From
Iigor.mikushkin <igor.mikushkin@gmail.com>
Date
Mar 25, 2011, 17:53 UTC
Message-ID
<1301075628970-6208585.post@n2.nabble.com>
In-Reply-To
<20110325165811.GB25851@sigill.intra.peff.net>
Jeff King wrote:
Show 51 quoted lines
> 
> On Fri, Mar 25, 2011 at 07:52:34AM -0700, igor.mikushkin wrote:
> 
> &gt; Why git silently replaces untracked files?
> &gt; 
> &gt; # mkdir test.git
> &gt; # mkdir 1
> &gt; # mkdir 2
> &gt; # echo 1 &gt; 1/test
> &gt; # echo 2 &gt; 2/test
> &gt; # cd test.git
> &gt; # git init --bare
> &gt; # cd ..
> &gt; # git clone test.git
> &gt; # cp -r test/.git 1
> &gt; # cp -r test/.git 2
> &gt; # cd 1
> &gt; # git add test
> &gt; # git commit -am 1
> &gt; # git push origin master
> &gt; # cd ../2
> &gt; # git pull
> &gt; # cat test
> &gt; 1
> &gt; 
> &gt; In my opinion it is wrong behavior.
> &gt; I've just lost important file due to it.
> &gt; 
> &gt; Should not &quot;git pull&quot; fail here?
> 
> Ick, definitely it's wrong behavior. The culprit seems to be a special
> code path for the initial pull which doesn't merge at all, but calls
> read-tree --reset. It should probably be:
> 
> diff --git a/git-pull.sh b/git-pull.sh
> index a3159c3..fb9e2df 100755
> --- a/git-pull.sh
> +++ b/git-pull.sh
> @@ -253,7 +253,7 @@ esac
>  if test -z &quot;$orig_head&quot;
>  then
>  	git update-ref -m &quot;initial pull&quot; HEAD $merge_head
> &quot;$curr_head&quot; &amp;&amp;
> -	git read-tree --reset -u HEAD || exit 1
> +	git read-tree -m -u HEAD || exit 1
>  	exit
>  fi
> 
> Though I don't know if there are any cases where the --reset would be
> beneficial over &quot;-m&quot;. I couldn't think of any.
> 

Thanks Jeff, My opinion is that you are right and merging is best here (Though just fail would be probably OK either). Love one line fixes.

Igor

-- View this message in context: http://git.661346.n2.nabble.com/Why-git-silently-replaces-untracked-files-tp6207950p6208585.html Sent from the git mailing list archive at Nabble.com.

Previous: Jeff KingNext: Jeff King
Message 3 of 8 in “Why git silently replaces untracked files?”
  1. igor.mikushkinMar 25, 2011
  2. Jeff KingMar 25, 2011
  3. igor.mikushkinMar 25, 2011
  4. Jeff KingMar 25, 2011
  5. 1/4 t7607: mark known breakage in test 11 as fixedJeff King, Mar 25, 2011
  6. 2/4 t7607: clean up stray untracked fileJeff King, Mar 25, 2011
  7. 3/4 merge: merge unborn index before setting refJeff King, Mar 25, 2011
  8. 4/4 pull: do not clobber untracked files on initial pullJeff King, Mar 25, 2011

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.