7 ms·
> git reset HEAD~ --hard Seems fairly magical compared to other stuff here. To me at least. Can anyone briefly explain what it does?
by ghiculescu 7y ago
> git reset HEAD~ --hard
Seems fairly magical compared to other stuff here. To me at least. Can anyone briefly explain what it does?
- q3k 7y agoHEAD~ means 'the second to last commit in the current branch' (ie. the second to last when you `git log`). git reset means 'point the current branch to this commit instead of wherver it's pointing now' (branches in git are just pointers to commits) git reset --hard means 'also reset the state of the checkout and staging area to be in sync with the commit' Thus, the entire spell means 'reset the current branch to make it point the the seecond-to-last-commit, also ensure my current checkout and staging area are in sync to that', or, in other words, fully forget and drop the latest commit.
- gwright 7y ago[Edit: It seems that I was mistaken but I'm leaving this up to illustrate the confusion. In my experience "second to last" isn't common and "next to last" is much more common, which I think is why I was confused because I thought they were different, but apparently they are the same. I wonder if there is a regional usage pattern to these phrases. ] This seems like mistake or a non-standard usage of the english phrase "second to last". Given a git log of: $ git log --oneline 15e0437 - (HEAD -> master) this is the third commit f82d1fd - this is the second commit 9180c17 - initial commit I would call "f82d1fd" the "next to last commit" and it can be referred to as HEAD~ I would call "9180c17" the "second to last commit" and it can be referred to as HEAD~2
- q3k 7y agoI don't know (definitely not a native English speaker), but Wikitionary seems to agree with me: https://en.wiktionary.org/wiki/second_to_last#English https://en.wiktionary.org/wiki/second_to_last#English .
- gwright 7y agoWell, I think you may be right. See my edit above. I suspect this is a regional usage pattern and I've just always been in places where "next to last" would be used and not "second to last" so I was thinking they were different, but they apparently are the same! Learn something new every day.
- gwright 7y agoHere is an ngram analysis with a British corpus https://books.google.com/ngrams/graph?content=second+last%2Csecond+to+last%2Cnext+to+last&year_start=1800&year_end=2000&corpus=18&smoothing=3&share=&direct_url=t1%3B%2Csecond%20last%3B%2Cc0%3B.t1%3B%2Csecond%20to%20last%3B%2Cc0%3B.t1%3B%2Cnext%20to%20last%3B%2Cc0#t1%3B%2Csecond%20last%3B%2Cc0%3B.t1%3B%2Csecond%20to%20last%3B%2Cc0%3B.t1%3B%2Cnext%20to%20last%3B%2Cc0 https://books.google.com/ngrams/graph?content=second+last%2C... And here is one with an American corpus: https://books.google.com/ngrams/graph?content=second+last%2Csecond+to+last%2Cnext+to+last&year_start=1800&year_end=2000&corpus=17&smoothing=3&share=&direct_url=t1%3B%2Csecond%20last%3B%2Cc0%3B.t1%3B%2Csecond%20to%20last%3B%2Cc0%3B.t1%3B%2Cnext%20to%20last%3B%2Cc0 https://books.google.com/ngrams/graph?content=second+last%2C...
- q3k 7y agoNice tool. You should expand the search range to include 2018/2019. Quite a significant change happened since then.
- deleted 7y ago[deleted]