* "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? @ 2009-01-02 19:57 chris 2009-01-02 22:36 ` Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: chris @ 2009-01-02 19:57 UTC (permalink / raw) To: git Does "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? It seems we have 2 ways to blow away work we haven't checked in yet then right? chris ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? 2009-01-02 19:57 "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? chris @ 2009-01-02 22:36 ` Junio C Hamano 2009-01-03 6:02 ` Sitaram Chamarty 0 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2009-01-02 22:36 UTC (permalink / raw) To: chris; +Cc: git chris@seberino.org writes: > Does "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? No, but "reset --hard" without a commit-ish defaults to HEAD so the first one and the last one are equivalent. > It seems we have 2 ways to blow away work we haven't checked in yet then right? Wrong. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? 2009-01-02 22:36 ` Junio C Hamano @ 2009-01-03 6:02 ` Sitaram Chamarty 2009-01-03 10:15 ` Junio C Hamano 0 siblings, 1 reply; 5+ messages in thread From: Sitaram Chamarty @ 2009-01-03 6:02 UTC (permalink / raw) To: git On 2009-01-02, Junio C Hamano <gitster@pobox.com> wrote: > chris@seberino.org writes: > >> Does "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? > > No, but "reset --hard" without a commit-ish defaults to HEAD so the first > one and the last one are equivalent. > >> It seems we have 2 ways to blow away work we haven't >> checked in yet then right? > > Wrong. Strictly as asked, yes, but what if he adds a "-f" to the middle command, making it "git checkout -f HEAD"? Wouldn't that be the same as the others then? I always thought they were eqvt... ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? 2009-01-03 6:02 ` Sitaram Chamarty @ 2009-01-03 10:15 ` Junio C Hamano 2009-01-03 12:27 ` Sitaram Chamarty 0 siblings, 1 reply; 5+ messages in thread From: Junio C Hamano @ 2009-01-03 10:15 UTC (permalink / raw) To: Sitaram Chamarty; +Cc: git Sitaram Chamarty <sitaramc@gmail.com> writes: >>> It seems we have 2 ways to blow away work we haven't >>> checked in yet then right? >> >> Wrong. > > Strictly as asked, yes, but what if he adds a "-f" to the > middle command, making it "git checkout -f HEAD"? Wouldn't > that be the same as the others then? Yeah, but comparing reset and checkout misses a whole _dimension_ in the revision space continuum. "git checkout <branch>" is primarily about checking out a different branch, aka "switching branches". When you switch branches, you generally do not want to lose your pending changes, but would want to take them with you. A typical scenario is that you start looking at one issue, you fiddle a few lines here and twiddle a few lines there, and as you dig deeper, you realize that whatever the final shape of the change you are going to make will be either (1) big enough to deserve its own branch created anew, or (2) better done as an extension to an existing branch. You realize that you are in the latter situation by noticing that the modification you were making will be helped by something you have implemented in the other branch but not yet available in the current one (typically the latter is 'master'). In such a case, you will "git checkout <the-appropriate-topic>" to switch to the branch, and you would want to take the change you already made to your work tree files when you do so. On the other hand, "git checkout -f <branch>" blows away your changes, but it still _is_ about switching to a different branch. Whether you use -f or not, you are allowed to ask to switch to the current branch by (1) naming the branch explicitly, i.e. "git checkout -f master", (2) using HEAD to mean the current one instead, or (3) omitting <branch> altogether. But that is there merely for consistency and, even though there may not make much sense to do so (because it is largely no-op except that you would get the "you are ahead by N" notice), there is no strong reason to forbid asking for a no-op. For that reason, "git checkout -f HEAD" is "blow away my changes". But it is merely a degenerated case of "switching to the current branch while blowing away my changes." "git reset --hard <commit>" is different. "reset" is primarily about pointing the tip of the current branch to somewhere else. While "git checkout <branch>" never changes what commit sits at the tip of any branch, "git reset <commit>" modifies it for the current branch (--hard variant matches the work tree files to the contents recorded by the resetted-to commit while at it). Again, you are allowed to ask to reset to the current HEAD by saying "reset --hard HEAD". That is a degenerated case of "resetting the tip of the current branch, while blowing away my changes". More general case would be "reset --hard <some-commit>" and it won't just blow away your changes (relative to the commit you started out with), but also blows away the history leading to the commit the branch tip used to point at. "checkout -f" and "reset --hard" work on different dimensions, and what they do intersect when (and only when) the <branch>/<commit> argument happen to be HEAD. "checkout -f <another>" and "reset --hard <another>" will do quite different things. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? 2009-01-03 10:15 ` Junio C Hamano @ 2009-01-03 12:27 ` Sitaram Chamarty 0 siblings, 0 replies; 5+ messages in thread From: Sitaram Chamarty @ 2009-01-03 12:27 UTC (permalink / raw) To: git On 2009-01-03, Junio C Hamano <gitster@pobox.com> wrote: > Sitaram Chamarty <sitaramc@gmail.com> writes: > >>>> It seems we have 2 ways to blow away work we haven't >>>> checked in yet then right? >>> >>> Wrong. >> >> Strictly as asked, yes, but what if he adds a "-f" to the >> middle command, making it "git checkout -f HEAD"? Wouldn't >> that be the same as the others then? > > Yeah, but comparing reset and checkout misses a whole _dimension_ in the > revision space continuum. [snip] > "checkout -f" and "reset --hard" work on different dimensions, and what > they do intersect when (and only when) the <branch>/<commit> argument > happen to be HEAD. "checkout -f <another>" and "reset --hard <another>" > will do quite different things. I teach git sometimes (internally) in my job. It seems to me that people who don't like TMTOWTDI get stuck on this "why are there 2 ways to do the same thing" aspect, even after I explain all the *other* uses of the two commands to show that they're actually quite different! Your use of "dimension" and "degenerate case" gave me an idea... most of my audience have decent math skills, so I bet they get it if I say these are like two quite different functions that just happen to intersect at x=0 :-) Thank you very much! ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-01-03 12:28 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-01-02 19:57 "git reset --hard" == "git checkout HEAD" == "git reset --hard HEAD" ??? chris 2009-01-02 22:36 ` Junio C Hamano 2009-01-03 6:02 ` Sitaram Chamarty 2009-01-03 10:15 ` Junio C Hamano 2009-01-03 12:27 ` Sitaram Chamarty
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).