Re: 'git checkout -f' versus 'git reset --hard'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]