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.
AbortingBut it misses the case when "something" switches from a file into a directory, which is probably a bug.
-Peff