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

Re: Help understanding git checkout behavior

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 11, 2012, 21:04 UTC
Message-ID
<7vobop5zmp.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAMUXYmUg12z8LUcFKwjH0Utrvxx0fa5Sne0u9adgoZ=oooBbig@mail.gmail.com>
Cláudio Lourenço <pt.smooke@gmail.com> writes:
> The deleted files from index, are just ignored (we think the bug comes
> from here).

Not really. In general, "git checkout b" (no path arguments, checking out the branch "b") will try to keep the local changes you made to the index and to the working tree for a path that are the same between your current branch and the branch "b". So it is perfectly normal to see:

        $ git checkout master
        $ git ls-files file
        file
	... ok, the master branch has "file"
	$ git diff master side | grep file
        ... ok, the side branch also has it and it is the same
        $ git rm file
        $ git checkout side
	D	file
	Switched to branch 'side'

So it actually _actively_ pays attention to paths deleted or modified in the index.

Another thing it does is when the local change to the index matches that of the branch you are switching to, checkout is allowed even if path is different between two branches.

When checking the differences between the two branches (the current and the new), unpack-trees notices that the path "something" is not present in "b" branch, and even though your current branch and the index differs (the index does not have "something" as you have removed it), it thinks it is OK for the result to not have it (which is correct). And when it does that, it forgets that a new path "something/f1" still needs to be kept (which is not correct), which is where the problem you are seeing comes from, methinks.

Previous: Cláudio LourençoNext: Junio C Hamano
Message 8 of 13 in “Help understanding git checkout behavior”
  1. Cláudio LourençoJun 11, 2012
  2. Konstantin KhomoutovJun 11, 2012
  3. konglu@minatec.inpg.frJun 11, 2012
  4. LeilaJun 11, 2012
  5. Jeff KingJun 11, 2012
  6. Junio C HamanoJun 11, 2012
  7. Cláudio LourençoJun 11, 2012
  8. Junio C HamanoJun 11, 2012
  9. Junio C HamanoJun 11, 2012
  10. Jeff KingJun 11, 2012
  11. Jeff KingJun 11, 2012
  12. Junio C HamanoJun 11, 2012
  13. Vincent van RavesteijnJun 11, 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.