{"thread":{"id":"1484","subject":"git checkout -f branch doesn't remove extra files","startedAt":"2005-08-12T17:31:17Z","lastAt":"2005-08-12T20:27:41Z","messageCount":2,"participants":["Luck, Tony","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"7134","messageId":"B8E391BBE9FE384DAA4C5C003888BE6F04214AC7@scsmsx401.amr.corp.intel.com","threadId":"1484","inReplyTo":null,"subject":"git checkout -f branch doesn't remove extra files","fromName":"Luck, Tony","fromEmail":"tony.luck@intel.com","sentAt":"2005-08-12T17:31:17Z","receivedAt":"2005-08-12T17:31:17Z","isPatch":false,"sender":{"key":"tony.luck@intel.com","avatar":"https://avatars.githubusercontent.com/u/5446021?v=4"},"body":"I've just got around to noticing some of the new (to\nme) features in git, and started experimenting with\nbranches.\n\nI see that when I switch view to a different\nbranch with:\n\n\t$ git checkout -f someoldbranch\n\nthat any files that exist in my previous branch view\nbut not in \"someoldbranch\" are not deleted.  I can\nfind and remove them easily with:\n\n\t$ git-ls-files --others | xargs rm -f\n\nbut I wondered whether this was a deliberate choice\n(to avoid clobbering .o files etc. for people who\nhave run a make in their tree).\n\nCurrently git-ls-files doesn't have a way to specify\na branch ... but it it did, the something like:\n\n\tcomm -1 <(git-ls-files -b oldbranch) \\\n\t\t  <(git-ls-files -b newbranch) | xargs rm -f\n\nwould clean up the spurious files.\n\n-Tony\n"},{"id":"7139","messageId":"7v8xz6uchu.fsf@assigned-by-dhcp.cox.net","threadId":"1484","inReplyTo":"B8E391BBE9FE384DAA4C5C003888BE6F04214AC7@scsmsx401.amr.corp.intel.com","subject":"Re: git checkout -f branch doesn't remove extra files","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-12T20:27:41Z","receivedAt":"2005-08-12T20:27:41Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Luck, Tony\" <tony.luck@intel.com> writes:\n\n> I see that when I switch view to a different\n> branch with:\n>\n> \t$ git checkout -f someoldbranch\n>\n> that any files that exist in my previous branch view\n> but not in \"someoldbranch\" are not deleted.\n>\n> ... I wondered whether this was a deliberate choice\n\nNot really.\n\nWhen possible, please use \"git checkout\" without -f.  That form\nuses \"git-read-tree -u -m\", which can tell from your current\nindex file what's changed and what's going away.  This is only\npossible if read-tree can rely on what is in your index file\nactually matches the status of your working tree, and the -f\nflag to checkout is to work around cases where you cannot give\nthat guarantee to read-tree and would want/need to start over\nfrom scratch.  With -f flag, you are telling git-read-tree to\nignore what is currently recorded in your index file, hence what\nshould be in your working tree before checkout.  There is no way\nfor git-read-tree to tell which are source files that exist only\nin the old thing you had checked out before (i.e. should be\nremoved) and which are files your build procedure left and/or\nfiles you made by hand outside of SCM control (i.e. should be\nkept) without that information, so that is why those files were\nleft behind.\n"}]}