github - git go back to a previous commit before reset hard -
i changed code, ran
git add . git commit -m "message1"
but after that, did
git reset hard git pull git push
(the push did nothing, of course.)
now want retrieve state of files @ point of commit "message1". how can that?
git reset hard
resets index (not working directory) state of branch called hard
. nothing changed: can simple git reset
reset index. nothing else has changed anyway.
if did git reset --hard
that’s different thing. reset index , uncommitted changes in working directory state of head, i.e. last commit of current branch. since made commit directly before command, lose nothing in case included changes of working directory in commit. if did not, you’re out of luck, , uncommitted changes never made index lost.
the git pull
fetch remote , merge changes branch, might have changed. since did commit locally, there 2 cases: date , nothing changed; there changes on remote , git created merge commit. in latter case, can revert using git reset --hard head@{1}
. can check reflog using git reflog
see head pointing previously.
as git push
, it’s not obvious doesn’t anything. actually, since made commit locally, should have done something. should have pushed commit , eventual merge commit (as per above) remote. in case, it’s not recommended go again (with above command) undo changes, since should never remove commits have published.