{"thread":{"id":"8265","subject":"Fwd: Problem: git doesn't update working dir (always) when checkout'ing other branch","startedAt":"2007-05-21T08:59:04Z","lastAt":"2007-05-22T08:04:37Z","messageCount":4,"participants":["Stian Haklev","Andy Parkins"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"42870","messageId":"566574ef0705210159m69d4e32cjd4bc5db66c1677b1@mail.gmail.com","threadId":"8265","inReplyTo":"566574ef0705210157j14cb7c56h62392c6193472a98@mail.gmail.com","subject":"Fwd: Problem: git doesn't update working dir (always) when checkout'ing other branch","fromName":"Stian Haklev","fromEmail":"shaklev@gmail.com","sentAt":"2007-05-21T08:59:04Z","receivedAt":"2007-05-21T08:59:04Z","isPatch":false,"sender":{"key":"shaklev@gmail.com","avatar":"https://gravatar.com/avatar/5bf03e21cb89e751dd1477528835dcb4a3b39805288525c230ce02f53a94e57d?d=mp&s=160"},"body":"Newbie to git, but I've been reading up on the docs and I really love\nboth the theory and what it let's you do (still confused by some\nissues like rebasing and stuff). For now I mostly use it on my own\nsmall projects (where I frequently make branches, merge, cherry-pick\netc), and also push it to  repo.or.cz.\n\nOne confusing thing to me is that if I am in a clean state (no updated\nfiles in working dir), and I checkout another branch (or another\ntreeish), sometimes git doesn't update the working dir, and sometimes\nit does. So for example in my own repo I do\n\n~wiki/> git status\nno files updated\n\n~wiki/> git checkout trying-new-feature\nchecked out\n\n~wiki/> git status\nno files updated\n\n(this is how it should be obviously - the working dir reflects the\nindex which is now pointing at trying-new-feature, but then...)\n\n~wiki/> git checkout master\nchecked out\n\n~wiki/> git status\nit then puts me directly into commit mode, with every file having a\nton of differences - because the files are still from\ntrying-new-feature and the index is pointing at master.\n\nIt also seems to do inconsistent things with files that exist in only\none of the branches - ie if switching back the file remains in the\ndirectory but is now an \"untracked\" file, etc.\n\nMaybe I am completely misunderstanding and there is something I should\ndo differently. It works out if I do git reset --hard, but it just\nseems so uneccessary. (As I said, in all cases the working dir is\ncompletely clean before doing the checkout).\n\nthank you\nStian\n"},{"id":"42874","messageId":"200705211016.58067.andyparkins@gmail.com","threadId":"8265","inReplyTo":"566574ef0705210159m69d4e32cjd4bc5db66c1677b1@mail.gmail.com","subject":"Re: Fwd: Problem: git doesn't update working dir (always) when checkout'ing other branch","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-05-21T09:16:54Z","receivedAt":"2007-05-21T09:16:54Z","isPatch":false,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Monday 2007 May 21, Stian Haklev wrote:\n\nWhat does \"git --version\" say?\n\n> ~wiki/> git checkout trying-new-feature\n> checked out\n> ~wiki/> git status\n> no files updated\n> ~wiki/> git checkout master\n> checked out\n> ~wiki/> git status\n> it then puts me directly into commit mode, with every file having a\n> ton of differences - because the files are still from\n> trying-new-feature and the index is pointing at master.\n\nSomething has gone very wrong here.  You are right to be confused, that is not \nwhat one would expect from git.  After a git-checkout you should expect that \nthe index is clean.\n\nDid you get any error messages during any of those operations?\n\nAre you sure you aren't doing something like\n  git checkout trying-new-feature -- list of files\nAs that would update the working tree but not the current HEAD, and would \ntherefore appear as changes to master.\n\nWhen you do the final git-status, are the files being listed in the \"Changed \nbut not updated\" section or the \"Changes to be committed\" section?\n\nCan you make a minimal test case? e.g.\n mkdir testing-git; cd testing-git\n git init\n date > file1\n git add file1\n git commit -a -m \"step1\"\n date >> file1\n git commit -a -m \"step2\"\n git checkout -b newbranch HEAD^\n date >> file1\n git commit -a -m \"step3\"\n git checkout master\n git checkout newbranch\n git status\n\n\n\nAndy\n-- \nDr Andy Parkins, M Eng (hons), MIET\nandyparkins@gmail.com\n"},{"id":"42943","messageId":"566574ef0705212105k1387cf41n18e076c0bdf47ec6@mail.gmail.com","threadId":"8265","inReplyTo":"200705211016.58067.andyparkins@gmail.com","subject":"Re: Fwd: Problem: git doesn't update working dir (always) when checkout'ing other branch","fromName":"Stian Haklev","fromEmail":"shaklev@gmail.com","sentAt":"2007-05-22T04:05:30Z","receivedAt":"2007-05-22T04:05:30Z","isPatch":false,"sender":{"key":"shaklev@gmail.com","avatar":"https://gravatar.com/avatar/5bf03e21cb89e751dd1477528835dcb4a3b39805288525c230ce02f53a94e57d?d=mp&s=160"},"body":"OK, I made the following script:\n\ndo.sh:\ngit --version > ../file1\ndate >> ../file1\ngit status >> ../file1\necho checking out works with old >> ../file1\ngit checkout works-with-old >> ../file1\ngit status >> ../file1\ngit checkout master >> ../file1\ngit status >> ../file1\ndate >> ../file1\n\nI ran it, and I got the following result:\nnurhaliza:~/wiki stian$ less ../file1\ngit version 1.5.2.14.g45bde\nTue May 22 11:05:19 WIT 2007\n# On branch master\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       do.sh\nnothing added to commit but untracked files present (use \"git add\" to track)\nchecking out works with old\n# On branch works-with-old\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       do.sh\nnothing added to commit but untracked files present (use \"git add\" to track)\n# On branch master\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n#       deleted:    NOTES\n#       modified:   display-page.rb\n#       deleted:    eee_darwin\n#       modified:   gui.rb\n#       modified:   htmlshrinker-data.rb\n#       modified:   htmlshrinker.rb\n#       modified:   mongrel-web-gui.rb\n#       modified:   mongrel-web.rb\n#       modified:   zarchive.rb\n#       new file:   zcompress.rb\n#       modified:   zdump-7z.rb\n#       modified:   zdump.rb\n#       modified:   zipdoc.rb\n#       deleted:    zutil.rb\n#\n# Untracked files:\n#   (use \"git add <file>...\" to include in what will be committed)\n#\n#       do.sh\nTue May 22 11:05:20 WIT 2007\n\n...\n\nI should add that I am working in OSX 10.4.9.\n\nThank you,\nStian\n"},{"id":"42961","messageId":"200705220904.39487.andyparkins@gmail.com","threadId":"8265","inReplyTo":"566574ef0705212105k1387cf41n18e076c0bdf47ec6@mail.gmail.com","subject":"Re: Fwd: Problem: git doesn't update working dir (always) when checkout'ing other branch","fromName":"Andy Parkins","fromEmail":"andyparkins@gmail.com","sentAt":"2007-05-22T08:04:37Z","receivedAt":"2007-05-22T08:04:37Z","isPatch":false,"sender":{"key":"andyparkins@gmail.com","avatar":null},"body":"On Tuesday 2007 May 22, Stian Haklev wrote:\n\n> git --version > ../file1\n\nGood stuff.  The \">\" only redirects stdout to file1; stderr would still be \nwritten to your terminal - did you notice any errors from this script?  Could \nyou run again, but append \"2>&1\" to the end of each redirecting line?\n\n> git status >> ../file1\nSeemed fine after this.\n\n> echo checking out works with old >> ../file1\n> git checkout works-with-old >> ../file1\nSeemed fine after this.\n\n> git status >> ../file1\nSeemed fine after this.\n\n> git checkout master >> ../file1\n> git status >> ../file1\n\nKaboom!\n\n> # On branch master \n> # Changes to be committed:\n> #   (use \"git reset HEAD <file>...\" to unstage)\n> #\n> #       deleted:    NOTES\n> #       modified:   display-page.rb\n> #       deleted:    eee_darwin\n> #       modified:   gui.rb\n> #       modified:   htmlshrinker-data.rb\n> #       modified:   htmlshrinker.rb\n> #       modified:   mongrel-web-gui.rb\n> #       modified:   mongrel-web.rb\n> #       modified:   zarchive.rb\n> #       new file:   zcompress.rb\n> #       modified:   zdump-7z.rb\n> #       modified:   zdump.rb\n> #       modified:   zipdoc.rb\n> #       deleted:    zutil.rb\n\nWow.  I've never seen anything like that.  Neither the index nor the working \ntree has actually been updated - but HEAD now points at master.\n\nWhat was the output of that last git-checkout (unfortunately it outputs to \nstderr not stdout, so you'll need the \"2>&1\" at the end of each line in your \nscript)?  git-checkout won't change HEAD unless the change of index and \nworking tree worked.  I can't see the path through the git-checkout script \nthat would have done what you're describing.  I think it's going to need a \nguru on this one, however, we'll keep at it until I can't think of any more \nquestions :-)\n\nDo you observe the same behaviour on all repositories or just this one \nparticular repository?\n\nWhat's the form of this repository?  That is to say, is works-with-old a \nbranch from master or is it an independent branch?  e.g.\n\n  0 -- * -- * -- * (master)             0 -- * -- * -- * (master)\n                                    or        \\\n  0 -- * -- * -- * (works-with-old)            * -- * -- * (works-with-old)\n                     \nI assume once you get into this broken state that running \"git-reset --hard\" \nrestores the working tree back to master?\n\nDoes changing that last checkout to \"git-checkout -f master\" improve things?\n\n\nAndy\n\n-- \nDr Andy Parkins, M Eng (hons), MIET\nandyparkins@gmail.com\n"}]}