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

Re: git checkout no longer warning about uncommitted/untracked files!

From
Jeff King <peff@peff.net>
Date
May 23, 2011, 21:10 UTC
Message-ID
<20110523211042.GC6281@sigill.intra.peff.net>
In-Reply-To
<4DDAC57D.9020809@lsrfire.ath.cx>
On Mon, May 23, 2011 at 10:37:17PM +0200, René Scharfe wrote:
Show 14 quoted lines
> 	$ echo 1 >a
> 	$ git add a
> 	$ git commit -m.
> 	[master (root-commit) b0e60d3] .
> 	 1 files changed, 1 insertions(+), 0 deletions(-)
> 	 create mode 100644 a
> 
> 	$ git branch x
> 	$ echo uncommitted >a
> 	$ echo untracked >b
> 
> 	$ git checkout x
> 	M	a
> 	Switched to branch 'x'

But you're not actually switching trees here, so there is by definition no merge that needs to happen, and the changes stay in place.

> 	$ cat a
> 	uncommitted
> 	$ cat b
> 	untracked

And here, there is no contention over "b" since git would never need to write it at all.

A better test would be:
  git init repo && cd repo
  echo 1 >a && git add a && git commit -m a1
  echo 2 >a && git add a && git commit -m a2
  git checkout -b check-uncommitted master^
  # should fail because we would have to merge
  echo 3 >a && git checkout master
  git checkout -f master
  echo 4 >b && git add b && git commit -m b4
  git checkout -b check-untracked master^
  echo untracked >b
  # should fail because we would overwrite untracked b
  git checkout master

And indeed, testing with v1.7.3., both of my "should fail" checkouts do fail, with the following messages respectively:

  error: Your local changes to the following files would be overwritten by checkout:
        a
  Please, commit your changes or stash them before you can switch branches.
  Aborting
and
  error: The following untracked working tree files would be overwritten by checkout:
        b
  Please move or remove them before you can switch branches.
  Aborting
So I still don't know what the bug is.
-Peff
Previous: René ScharfeNext: funeeldy
Message 3 of 8 in “git checkout no longer warning about uncommitted/untracked files!”
  1. funeeldyMay 23, 2011
  2. René ScharfeMay 23, 2011
  3. Jeff KingMay 23, 2011
  4. funeeldyMay 23, 2011
  5. funeeldyMay 23, 2011
  6. Jeff KingMay 23, 2011
  7. Marlene CoteMay 23, 2011
  8. Jeff KingMay 23, 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.