Zulip Chat Archive

Stream: general

Topic: git gone wrong


Eric Rodriguez (Nov 09 2021 at 17:57):

erm, I seem to have added every person who has pushed code in the past week to #9779 by a bad merge commit. should I just nuke it from the sky or is there a better way to fix it?

Eric Wieser (Nov 09 2021 at 19:21):

git reset --hard HEAD@{1} should take you back to where you were before the merge commit, where you can try again

Eric Wieser (Nov 09 2021 at 19:21):

(but will discard all your changes you made during the merge)

Eric Rodriguez (Nov 09 2021 at 19:49):

that's a really nice tip, thanks

Eric Rodriguez (Nov 09 2021 at 19:49):

I did reset --hard HEAD~423 and accidentally had to redo the commit... oh well

Eric Wieser (Nov 09 2021 at 19:51):

Note that @{n} means "where I was n operations ago" as opposed to ~n which means "n commits ago"

Eric Wieser (Nov 09 2021 at 19:51):

git reflog shows you what those operations were

Arthur Paulino (Nov 09 2021 at 19:53):

Or you can run git log and manually copy the commit hash (say abc123) then do a git reset abc123 --hard. It's useful if you want to double check the commit message before doing the hard reset

Eric Wieser (Nov 09 2021 at 20:06):

reflog shows the commit messages too

Arthur Paulino (Nov 09 2021 at 22:36):

True! And the abbreviated commit hashes shown by reflog work as inputs for git reset too

Sebastian Ullrich (Nov 09 2021 at 22:45):

One of my "favorite" git tricks is that @ is a shorthand for HEAD, so you can also use @@{1} to go back one operation

Mac (Nov 10 2021 at 07:05):

Only slightly related comment: this thread for some reason made me realize that the "reflog" of "git reflog" is suppose to be read as ref-log instead of re-flog, the latter being how I had read it forever. I had always thought it strange that git had chose "flogging" for part of its jargon. :rolling_on_the_floor_laughing:


Last updated: Dec 20 2023 at 11:08 UTC