{"thread":{"id":"7787","subject":"git-checkout changes the index but not the checked out files?","startedAt":"2007-04-22T23:25:01Z","lastAt":"2007-04-23T20:16:11Z","messageCount":8,"participants":["Martin Langhoff","Junio C Hamano","Linus Torvalds","Uwe Kleine-König"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"40164","messageId":"46a038f90704221625k216864cdwb2b35bc035fac7e9@mail.gmail.com","threadId":"7787","inReplyTo":null,"subject":"git-checkout changes the index but not the checked out files?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-04-22T23:25:01Z","receivedAt":"2007-04-22T23:25:01Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"I am a bit confused by git-checkout behaviour in the following scenario.\n\n$ git version\ngit version 1.5.1.gf8ce1\n\n$ git-branch\n  mdl17-polhn\n* mdl18-local\n  mdl18-topnz\n\n$ git-status\n<shows a clean status>\n\n# checkout an upstream branch to test that it has a bug\n$ git-checkout origin/MOODLE_18_STABLE\n$ git-status\n<shows a clean status>\n\n# switch back to our local branch to test that the bug is gone\n$ git-checkout mdl18-local\n$ git-status\n<shows a very dirty status - the index has changed but the files\nweren't updated to the contents of mdl18-local>\n$ git-reset --hard # this fixes things back to normal\n\nIs the bug in git-checkout or in my understanding? ;-) Perhaps I am\nmodelling my use of git-checkout on how I used cg-switch and that's\nwrong. But reading the man page, it says:\n\nWhen <paths> are not given, this command switches branches by\nupdating the index and working tree to reflect the specified\nbranch, <branch>, and updating HEAD to be <branch>\n\ncheers,\n\n\nmartin\n"},{"id":"40165","messageId":"7virbokmx1.fsf@assigned-by-dhcp.cox.net","threadId":"7787","inReplyTo":"46a038f90704221625k216864cdwb2b35bc035fac7e9@mail.gmail.com","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-22T23:30:02Z","receivedAt":"2007-04-22T23:30:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Martin Langhoff\" <martin.langhoff@gmail.com> writes:\n\n> # checkout an upstream branch to test that it has a bug\n> $ git-checkout origin/MOODLE_18_STABLE\n> $ git-status\n> <shows a clean status>\n>\n> # switch back to our local branch to test that the bug is gone\n> $ git-checkout mdl18-local\n> $ git-status\n> <shows a very dirty status - the index has changed but the files\n> weren't updated to the contents of mdl18-local>\n\nShouldn't happen.  Details?\n"},{"id":"40168","messageId":"46a038f90704221717i8e5c1bkff066dcbdb0a0523@mail.gmail.com","threadId":"7787","inReplyTo":"7virbokmx1.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-04-23T00:17:19Z","receivedAt":"2007-04-23T00:17:19Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 4/23/07, Junio C Hamano <junkio@cox.net> wrote:\n> Shouldn't happen.  Details?\n\nHmnmm. Not sure really what to look for ;-)\n\nIf I try it on my git checkout (checkout origin/pu and then checkout\nmaster) nothing strange happens. But if I do it on my project,\n(fetchable from http://git.catalyst.net.nz/moodle-r2.git ) between a\n\"local\" mdl18-local and origin/MOODLE_18_STABLE, it all goes weird.\n\nJust re-ran the process with bash -x, and it switches to a detached\nhead when going to origin/MOODLE_18_STABLE (as expected). And when\nswitching back, it all looks _almost_ reasonable except that there's a\ncall to git-read-tree with -m and 2 sha1s. It is trying to merge\nmdl18-local and mdl18-topnz apparently.\n\nIn fact:\n\n - I am on mdl18-local\n - git-status is clean\n - git checkout mdl18-local reports \"Already on branch \"mdl18-local\"\nbut it does a merge anyway\n\nThe problem seems to be that the SHA1 returned here is bogus:\n\n   $ git-rev-parse --verify 'mdl18-local^0'\n   warning: refname 'mdl18-local' is ambiguous.\n   a26c09be05a08e5f911ef84b5f8010ba155ea77d\n\nIf I disambiguate it one way or the other, I get correct results\n\n   $ git-rev-parse --verify 'refs/heads/mdl18-local^0'\n   634dcf72a31d0c75a98c1d69dd4763def7bcf2d5\n   $ git-rev-parse --verify 'remotes/origin/mdl18-local^0'\n   6e6ae22a2960d3ac321acd1cdfa09f23068f33b4\n\nbut the ambiguous \"git-rev-parse --verify 'mdl18-local^0'\" returns the\nSHA1 for a head called 'mdl18-topnz' that I am not asking for. Why?\n\ncheers,\n\n\nm\n"},{"id":"40169","messageId":"7vabx0kk4z.fsf@assigned-by-dhcp.cox.net","threadId":"7787","inReplyTo":"46a038f90704221717i8e5c1bkff066dcbdb0a0523@mail.gmail.com","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-04-23T00:30:04Z","receivedAt":"2007-04-23T00:30:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Martin Langhoff\" <martin.langhoff@gmail.com> writes:\n\n> but the ambiguous \"git-rev-parse --verify 'mdl18-local^0'\" returns the\n> SHA1 for a head called 'mdl18-topnz' that I am not asking for. Why?\n\nMaybe you have a branch that is exactly the same name as a tag?\n"},{"id":"40170","messageId":"46a038f90704221745h1bf2955cyfb40f6e8c08a336d@mail.gmail.com","threadId":"7787","inReplyTo":"7vabx0kk4z.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-04-23T00:45:06Z","receivedAt":"2007-04-23T00:45:06Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 4/23/07, Junio C Hamano <junkio@cox.net> wrote:\n> > but the ambiguous \"git-rev-parse --verify 'mdl18-local^0'\" returns the\n> > SHA1 for a head called 'mdl18-topnz' that I am not asking for. Why?\n>\n> Maybe you have a branch that is exactly the same name as a tag?\n\nNope - none of the tags look _anything_ like mdl18-local. See\nhttp://git.catalyst.net.nz/gitweb?p=moodle-r2.git;a=tags\n\nI think mdl18-topnz was the first local branch I created in this checkout.\n\nHmmmm. There was a .git/mdl18-local file that had the bogus SHA1 in\nit: a26c09be05a08e5f911ef84b5f8010ba155ea77d . I don't know how it got\nthere and how it had the wrong sha1 in it. Removing it has fixed it.\n\nThe _really_ strange bit is that it was attempting to merge 2 heads of\nthe same name. It'd probably be something to block...\n\ncheers,\n\n\nmartin\n"},{"id":"40205","messageId":"alpine.LFD.0.98.0704230747110.9964@woody.linux-foundation.org","threadId":"7787","inReplyTo":"46a038f90704221745h1bf2955cyfb40f6e8c08a336d@mail.gmail.com","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-04-23T14:53:57Z","receivedAt":"2007-04-23T14:53:57Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 23 Apr 2007, Martin Langhoff wrote:\n> \n> The _really_ strange bit is that it was attempting to merge 2 heads of\n> the same name. It'd probably be something to block...\n\nNo, \"git-read-tree -m A B\" is not a \"merge\" in the sense you're thinking, \nit's a \"fast-forward merge\", ie just a \"move from A to B\"\n\nSo read-tree has three \"merges\": a one-way merge (which just merges with \nthe old index _stat_ contents but otherwise just reads in the new tree), a \ntwo-way merge (a \"move from A to B\") that checks that all paths that are \ndifferent in the two trees match the index in the old one, and the \"real\"\nmerge, aka the three-way thing (and even that is actially \"four-way\", \nsince it also checks the index for matchingness)\n\nSo when we move from one head to another, we do that two-way thing. And if \nA and B are the same, doesn't really do anything, but there's also no \npoint to try to avoid doing it.\n\n\t\tLinus\n"},{"id":"40223","messageId":"20070423183551.GB25465@informatik.uni-freiburg.de","threadId":"7787","inReplyTo":"46a038f90704221745h1bf2955cyfb40f6e8c08a336d@mail.gmail.com","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Uwe Kleine-König","fromEmail":"ukleinek@informatik.uni-freiburg.de","sentAt":"2007-04-23T18:35:51Z","receivedAt":"2007-04-23T18:35:51Z","isPatch":false,"sender":{"key":"u.kleine-koenig@pengutronix.de","avatar":"https://gravatar.com/avatar/354b5e3ceb2806a2f1e1e382ac29ddbdad18288654da62b61eb13583a857eee7?d=mp&s=160"},"body":"Hallo,\n\nMartin Langhoff wrote:\n> Hmmmm. There was a .git/mdl18-local file that had the bogus SHA1 in\n> it: a26c09be05a08e5f911ef84b5f8010ba155ea77d . I don't know how it got\n> there and how it had the wrong sha1 in it. \nI already saw this, too.  In my case it was the result from making \n\n\tgit update-ref $branch ...\n\nand I forgot to prefix $branch with refs/heads.\n\nBest regards\nUwe\n\n-- \nUwe Kleine-König\n\nhttp://www.google.com/search?q=e+%5E+%28i+pi%29\n"},{"id":"40236","messageId":"46a038f90704231316r3a94c46cl8e1dd2a9dbccbea@mail.gmail.com","threadId":"7787","inReplyTo":"alpine.LFD.0.98.0704230747110.9964@woody.linux-foundation.org","subject":"Re: git-checkout changes the index but not the checked out files?","fromName":"Martin Langhoff","fromEmail":"martin.langhoff@gmail.com","sentAt":"2007-04-23T20:16:11Z","receivedAt":"2007-04-23T20:16:11Z","isPatch":false,"sender":{"key":"martin.langhoff@gmail.com","avatar":"https://gravatar.com/avatar/1e3f311b6c4c15836501901ca58f8c0b0667246488084ba524d8bc9867e22fd9?d=mp&s=160"},"body":"On 4/24/07, Linus Torvalds <torvalds@linux-foundation.org> wrote:\n> On Mon, 23 Apr 2007, Martin Langhoff wrote:\n> > The _really_ strange bit is that it was attempting to merge 2 heads of\n> > the same name. It'd probably be something to block...\n>\n> No, \"git-read-tree -m A B\" is not a \"merge\" in the sense you're thinking,\n> it's a \"fast-forward merge\", ie just a \"move from A to B\"\n...\n> So when we move from one head to another, we do that two-way thing. And if\n> A and B are the same, doesn't really do anything, but there's also no\n> point to try to avoid doing it.\n\nYup - except that the logic in git-commit wasn't expecting this at\nall, so it never said \"fast-forwarding\" and most importantly, it\nchanged the index, and the checked out files, but didn't update the\nhead it was aiming for.\n\nThere is definitely a bug when heads are ambiguous. Will try and find\nsome time to fix it up in the coming days but I'm quite cornered with\nwork here so if anyone wants to have a look at it...\n\ncheers,\n\n\nmartin\n"}]}