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, 18:56 UTC
Message-ID
<7vaa097k3q.fsf@alter.siamese.dyndns.org>
In-Reply-To
<CAA3EhH+iD-sS-3Sg4HJDHgs4Deg2=qbCuJD4UwZWtGQsKbV5aA@mail.gmail.com>
Leila <muhtasib@gmail.com> writes:
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?

If there were "git commit" immediately before the "git checkout b" to check out the branch "b", then something/f1 would be among the data committed to the branch "master", and it is perfectly fine to remove it in order to check out branch "b" that does not have the directory "something" or file in it "something/f1".

But if there is "something/f1" that is not yet committed, the command should have refused to check out the branch "b", which I think is what Cláudio is talking about. It looks like a bug to me.

Show 63 quoted lines
>
>
> On Mon, Jun 11, 2012 at 2:21 PM,  <konglu@minatec.inpg.fr> wrote:
>>
>> Cláudio Lourenço <pt.smooke@gmail.com> a écrit :
>>
>>
>>> The project was going pretty fine, till we start modeling the checkout
>>> operation. We are with some problems finding useful information about
>>> the properties that have to be satisfied when the "git checkout" is
>>> performed. We have concluded that if everything that is on index is
>>> commited then we have no problems making checkout.
>>> The problem is when we have something on index that is not updated
>>> with the last commit. We cannot find a general property that says when
>>> checkout can be performed. We have even found some files that are
>>> lost, like in this case:
>>>
>>> smooke  teste $ git init
>>> Initialized empty Git repository in /home/smooke/Dropbox/teste/.git/
>>> smooke  teste $ touch f
>>> smooke  teste $ echo a > f
>>> smooke  teste $ git add f
>>> smooke  teste $ git commit -m 'first commit'
>>> [master (root-commit) dab04b9] first commit
>>>  1 files changed, 1 insertions(+), 0 deletions(-)
>>>  create mode 100644 f
>>> smooke  teste $ git branch b
>>> smooke  teste $ touch something
>>> smooke  teste $ echo b > something
>>> smooke  teste $ git add something
>>> smooke  teste $ git commit -m 'something added'
>>> [master 9f2b8ad] something added
>>>  1 files changed, 1 insertions(+), 0 deletions(-)
>>>  create mode 100644 something
>>> 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
>>> smooke  teste $ git checkout master
>>> Switched to branch 'master'
>>> smooke  teste $ ls
>>> f  something
>>> smooke  teste $ cat something
>>> b
>>
>>
>> What do you mean by "lost files" ? Are you talking about "something"
>> that doesn't appear on branch 'b' ?
>>
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe git" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Jeff KingNext: Cláudio Lourenço
Message 6 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.