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

Re: Help understanding git checkout behavior

From
Jeff King <peff@peff.net>
Date
Jun 11, 2012, 18:55 UTC
Message-ID
<20120611185507.GF20134@sigill.intra.peff.net>
In-Reply-To
<CAA3EhH+iD-sS-3Sg4HJDHgs4Deg2=qbCuJD4UwZWtGQsKbV5aA@mail.gmail.com>
On Mon, Jun 11, 2012 at 02:34:01PM -0400, Leila wrote:
Show 5 quoted lines
> When you create a branch, it will contain everything committed on the
> branch you created it from at that given point. So if you commit more
> things on the master branch like you have done (after creating b),
> then switch to branch b, they won't appear. This is the correct
> behavior. Does that answer your question?
No, the problem is more subtle:
Show 12 quoted lines
> >> smooke  teste $ git rm something
> >> rm 'something'
> >> smooke  teste $ mkdir something
> >> smooke  teste $ cd something/
> >> smooke  something $ touch f1
> >> smooke  something $ echo c > f1
> >> smooke  something $ cd ..
> >> smooke  teste $ git add something/f1
> >> smooke  teste $ git checkout b
> >> Switched to branch 'b'
> >> smooke  teste $ ls
> >> f

We have lost "something/f1" during the switch, which was not committed anywhere. This is presumably an error because we see that "something" used to be tracked, and now we are tracking something different there.

If we had put some new content into the file "something", git would rightfully complain with:

  $ git checkout b
  error: Your local changes to the following files would be overwritten
  by checkout:
          something
  Please, commit your changes or stash them before you can switch branches.
  Aborting

But it misses the case when "something" switches from a file into a directory, which is probably a bug.

-Peff
Previous: LeilaNext: Junio C Hamano
Message 5 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.