* 'git checkout -f' versus 'git reset --hard'
@ 2007-04-05 13:36 Bill Lear
2007-04-05 13:43 ` Jeff King
2007-04-05 15:43 ` Linus Torvalds
0 siblings, 2 replies; 4+ messages in thread
From: Bill Lear @ 2007-04-05 13:36 UTC (permalink / raw)
To: git
After a failed merge, I want to undo things. I typically use git
reset --hard, and it works like a charm. Others have tried to use git
checkout -f, but I have cautioned that git reset --hard is really the
way to do it. Is there a difference here, or are they equivalent?
Bill
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 'git checkout -f' versus 'git reset --hard'
2007-04-05 13:36 'git checkout -f' versus 'git reset --hard' Bill Lear
@ 2007-04-05 13:43 ` Jeff King
2007-04-05 15:29 ` Shawn O. Pearce
2007-04-05 15:43 ` Linus Torvalds
1 sibling, 1 reply; 4+ messages in thread
From: Jeff King @ 2007-04-05 13:43 UTC (permalink / raw)
To: Bill Lear; +Cc: git
On Thu, Apr 05, 2007 at 08:36:09AM -0500, Bill Lear wrote:
> After a failed merge, I want to undo things. I typically use git
> reset --hard, and it works like a charm. Others have tried to use git
> checkout -f, but I have cautioned that git reset --hard is really the
> way to do it. Is there a difference here, or are they equivalent?
Skimming through the code (and looking at the output of sh -x), it looks
like both just end up executing git-read-tree --reset -u $HEAD.
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 'git checkout -f' versus 'git reset --hard'
2007-04-05 13:43 ` Jeff King
@ 2007-04-05 15:29 ` Shawn O. Pearce
0 siblings, 0 replies; 4+ messages in thread
From: Shawn O. Pearce @ 2007-04-05 15:29 UTC (permalink / raw)
To: Jeff King; +Cc: Bill Lear, git
Jeff King <peff@peff.net> wrote:
> On Thu, Apr 05, 2007 at 08:36:09AM -0500, Bill Lear wrote:
>
> > After a failed merge, I want to undo things. I typically use git
> > reset --hard, and it works like a charm. Others have tried to use git
> > checkout -f, but I have cautioned that git reset --hard is really the
> > way to do it. Is there a difference here, or are they equivalent?
>
> Skimming through the code (and looking at the output of sh -x), it looks
> like both just end up executing git-read-tree --reset -u $HEAD.
Sure, but git-reset also whacks MERGE_MSG, rr-cache/MERGE_RR,
SQUASH_MSG, SQUASH_HEAD. Maybe checkout should do the same.
I guess checkout -f is fine, and does the job, but usually we say
reset --hard. :-)
--
Shawn.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: 'git checkout -f' versus 'git reset --hard'
2007-04-05 13:36 'git checkout -f' versus 'git reset --hard' Bill Lear
2007-04-05 13:43 ` Jeff King
@ 2007-04-05 15:43 ` Linus Torvalds
1 sibling, 0 replies; 4+ messages in thread
From: Linus Torvalds @ 2007-04-05 15:43 UTC (permalink / raw)
To: Bill Lear; +Cc: git
On Thu, 5 Apr 2007, Bill Lear wrote:
>
> After a failed merge, I want to undo things. I typically use git
> reset --hard, and it works like a charm. Others have tried to use git
> checkout -f, but I have cautioned that git reset --hard is really the
> way to do it. Is there a difference here, or are they equivalent?
They are equivalent, but *only* if not given any other arguments (or if
given "HEAD", which is obviously the default).
HOWEVER! If you give them an argument, they work very differently. So
git checkout -f <branchname>
git reset --hard <branchname>
are fundamentally different operations: the "git checkout -f" thing will
*switch* to the named branch (or create a detached HEAD if it's just a
random commit SHA1 and not a branchname), while the "git reset --hard"
thing will *force* the current branch top commit to the same as for
<branchname>.
It just so happens that without any branchname they both default to the
"current branch", and then the two end up doing the exact same thing, even
though conceptually they are very different operations.
So they really are fundamentally different, it's just that for the common
special case they end up doing the same thing.
Linus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-04-05 15:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-05 13:36 'git checkout -f' versus 'git reset --hard' Bill Lear
2007-04-05 13:43 ` Jeff King
2007-04-05 15:29 ` Shawn O. Pearce
2007-04-05 15:43 ` Linus Torvalds
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).