Recover from git reset --hard?

后端 未结 22 2823
盖世英雄少女心
盖世英雄少女心 2020-11-22 00:52

Is there any way to recover uncommitted changes to the working directory from a git reset --hard HEAD?

22条回答
  •  日久生厌
    2020-11-22 01:56

    answer from this SO

    $ git reflog show
    
    4b6cf8e (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to origin/master
    295f07d HEAD@{1}: pull: Merge made by the 'recursive' strategy.
    7c49ec7 HEAD@{2}: commit: restore dependencies to the User model
    fa57f59 HEAD@{3}: commit: restore dependencies to the Profile model
    3431936 HEAD@{4}: commit (amend): restore admin
    033f5c0 HEAD@{5}: commit: restore admin
    ecd2c1d HEAD@{6}: commit: re-enable settings app
    
    # the commit the HEAD to be pointed to is 7c49ec7 (restore dependencies to the User model)
    
    $ git reset HEAD@{2}
    

    You got your day back! :)

提交回复
热议问题