How can I undo git reset --hard HEAD~1?

后端 未结 18 3108
逝去的感伤
逝去的感伤 2020-11-22 00:21

Is it possible to undo the changes caused by the following command? If so, how?

git reset --hard HEAD~1
18条回答
  •  一向
    一向 (楼主)
    2020-11-22 00:54

    Example of IRL case:

    $ git fsck --lost-found

    Checking object directories: 100% (256/256), done.
    Checking objects: 100% (3/3), done.
    dangling blob 025cab9725ccc00fbd7202da543f556c146cb119
    dangling blob 84e9af799c2f5f08fb50874e5be7fb5cb7aa7c1b
    dangling blob 85f4d1a289e094012819d9732f017c7805ee85b4
    dangling blob 8f654d1cd425da7389d12c17dd2d88d318496d98
    dangling blob 9183b84bbd292dcc238ca546dab896e073432933
    dangling blob 1448ee51d0ea16f259371b32a557b60f908d15ee
    dangling blob 95372cef6148d980ab1d7539ee6fbb44f5e87e22
    dangling blob 9b3bf9fb1ee82c6d6d5ec9149e38fe53d4151fbd
    dangling blob 2b21002ca449a9e30dbb87e535fbd4e65bac18f7
    dangling blob 2fff2f8e4ea6408ac84a8560477aa00583002e66
    dangling blob 333e76340b59a944456b4befd0e007c2e23ab37b
    dangling blob b87163c8def315d40721e592f15c2192a33816bb
    dangling blob c22aafb90358f6bf22577d1ae077ad89d9eea0a7
    dangling blob c6ef78dd64c886e9c9895e2fc4556e69e4fbb133
    dangling blob 4a71f9ff8262701171d42559a283c751fea6a201
    dangling blob 6b762d368f44ffffd441e5b8eae6a7b611335b49a2
    dangling blob 724d23914b48443b19eada79c3eb1813c3c67fed
    dangling blob 749ffc9a412e7584245af5106e78167b9480a27b
    dangling commit f6ce1a403399772d4146d306d5763f3f5715cb5a    <- it's this one
    

    $ git show f6ce1a403399772d4146d306d5763f3f5715cb5a

    commit f6ce1a403399772d4146d306d5763f3f5715cb5a
    Author: Stian Gudmundsen Høiland 
    Date:   Wed Aug 15 08:41:30 2012 +0200
    
        *MY COMMIT MESSAGE IS DISPLAYED HERE*
    
    diff --git a/Some.file b/Some.file
    new file mode 100644
    index 0000000..15baeba
    --- /dev/null
    +++ b/Some.file
    *THE WHOLE COMMIT IS DISPLAYED HERE*
    

    $ git rebase f6ce1a403399772d4146d306d5763f3f5715cb5a

    First, rewinding head to replay your work on top of it...
    Fast-forwarded master to f6ce1a403399772d4146d306d5763f3f5715cb5a.
    

提交回复
热议问题