search

Home  >  Q&A  >  body text

git reset --hard 回滚以后 以后怎么再回去?

git reset --hard 回滚到之前的版本以后,怎么撤销这一步回滚操作?

PHP中文网PHP中文网2878 days ago933

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-02 09:22:55

    It can be restored through reflog, provided that the lost branch or commit information has not been cleared by git gc

    Under normal circumstances, GC will keep those useless objects for a long time before clearing them

    You can use git reflog show or git log -g command to see all operation logs

    The recovery process is simple:

    1. Use the git log -g command to find the commitid corresponding to the information that needs to be restored. You can identify it by the time and date of submission. Find the commitid corresponding to the commit before executing reset --hard

    2. Create a new branch through git branch recover_branch commitid

    In this way, the code up to commitid, various submission records and other information are restored to the recover_branch branch.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-02 09:22:55

    git stash save
    git reflog 
    git checkout
    git branch 
    

    stash your current dirty content. Use reflog to find the commit you want to go back to, checkout it and then create a branch to merge with the original branch.

    reply
    0
  • Cancelreply