{"thread":{"id":"7525","subject":"'git checkout -f' versus 'git reset --hard'","startedAt":"2007-04-05T13:36:09Z","lastAt":"2007-04-05T15:43:15Z","messageCount":4,"participants":["Bill Lear","Jeff King","Shawn O. Pearce","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"38703","messageId":"17940.64329.10165.993967@lisa.zopyra.com","threadId":"7525","inReplyTo":null,"subject":"'git checkout -f' versus 'git reset --hard'","fromName":"Bill Lear","fromEmail":"rael@zopyra.com","sentAt":"2007-04-05T13:36:09Z","receivedAt":"2007-04-05T13:36:09Z","isPatch":false,"sender":{"key":"rael@zopyra.com","avatar":"https://gravatar.com/avatar/c4f2d2790ca3828d3b4e7dfebabf61d2fe94fd82fa49cdac2a5295dd2d46a874?d=mp&s=160"},"body":"After a failed merge, I want to undo things.  I typically use git\nreset --hard, and it works like a charm.  Others have tried to use git\ncheckout -f, but I have cautioned that git reset --hard is really the\nway to do it.  Is there a difference here, or are they equivalent?\n\n\nBill\n"},{"id":"38704","messageId":"20070405134311.GA18163@coredump.intra.peff.net","threadId":"7525","inReplyTo":"17940.64329.10165.993967@lisa.zopyra.com","subject":"Re: 'git checkout -f' versus 'git reset --hard'","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2007-04-05T13:43:12Z","receivedAt":"2007-04-05T13:43:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 05, 2007 at 08:36:09AM -0500, Bill Lear wrote:\n\n> After a failed merge, I want to undo things.  I typically use git\n> reset --hard, and it works like a charm.  Others have tried to use git\n> checkout -f, but I have cautioned that git reset --hard is really the\n> way to do it.  Is there a difference here, or are they equivalent?\n\nSkimming through the code (and looking at the output of sh -x), it looks\nlike both just end up executing git-read-tree --reset -u $HEAD.\n\n-Peff\n"},{"id":"38710","messageId":"20070405152925.GG5436@spearce.org","threadId":"7525","inReplyTo":"20070405134311.GA18163@coredump.intra.peff.net","subject":"Re: 'git checkout -f' versus 'git reset --hard'","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-04-05T15:29:25Z","receivedAt":"2007-04-05T15:29:25Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Jeff King <peff@peff.net> wrote:\n> On Thu, Apr 05, 2007 at 08:36:09AM -0500, Bill Lear wrote:\n> \n> > After a failed merge, I want to undo things.  I typically use git\n> > reset --hard, and it works like a charm.  Others have tried to use git\n> > checkout -f, but I have cautioned that git reset --hard is really the\n> > way to do it.  Is there a difference here, or are they equivalent?\n> \n> Skimming through the code (and looking at the output of sh -x), it looks\n> like both just end up executing git-read-tree --reset -u $HEAD.\n\nSure, but git-reset also whacks MERGE_MSG, rr-cache/MERGE_RR,\nSQUASH_MSG, SQUASH_HEAD.  Maybe checkout should do the same.\n\nI guess checkout -f is fine, and does the job, but usually we say\nreset --hard.  :-)\n\n-- \nShawn.\n"},{"id":"38714","messageId":"Pine.LNX.4.64.0704050837330.6730@woody.linux-foundation.org","threadId":"7525","inReplyTo":"17940.64329.10165.993967@lisa.zopyra.com","subject":"Re: 'git checkout -f' versus 'git reset --hard'","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2007-04-05T15:43:15Z","receivedAt":"2007-04-05T15:43:15Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Thu, 5 Apr 2007, Bill Lear wrote:\n>\n> After a failed merge, I want to undo things.  I typically use git\n> reset --hard, and it works like a charm.  Others have tried to use git\n> checkout -f, but I have cautioned that git reset --hard is really the\n> way to do it.  Is there a difference here, or are they equivalent?\n\nThey are equivalent, but *only* if not given any other arguments (or if \ngiven \"HEAD\", which is obviously the default).\n\nHOWEVER! If you give them an argument, they work very differently. So\n\n\tgit checkout -f <branchname>\n\tgit reset --hard <branchname>\n\nare fundamentally different operations: the \"git checkout -f\" thing will \n*switch* to the named branch (or create a detached HEAD if it's just a \nrandom commit SHA1 and not a branchname), while the \"git reset --hard\" \nthing will *force* the current branch top commit to the same as for\n<branchname>.\n\nIt just so happens that without any branchname they both default to the \n\"current branch\", and then the two end up doing the exact same thing, even \nthough conceptually they are very different operations.\n\nSo they really are fundamentally different, it's just that for the common \nspecial case they end up doing the same thing.\n\n\t\tLinus\n"}]}