f origin master' any way to restore?

I commited using 'git push -f origin master' and it deleted all my previous commits. Is there any way I can restore them or at least show all my previous commits?


你可以试试这个:

$ git reflog                   # show working tree, copy the last commit-hash that have all codes
$ git checkout <commit-hash>   # checkout to that commit, now you've all codes
$ git checkout -b new-master   # create a new branch named new-master & checkout.
$ git branch -D master         # delete your local master branch
$ git checkout -b master       # create master from current commit and checkout to master
$ git push -f origin master    # push all the codes to remote  

Use git reflog to see missing commits.

Then, find the commits you want and use git reset in order to reset them.

After reseting the deleted commits, then push the changes to the origin using git push origin master


You can use the reflog from either your local git reflog or remote repository and find the commit that you want to revert to;

git reflog //at local level
git reflog show remotes/origin/master // at remote level: 

The reflog shows a list of all changes to HEAD in reverse chronological oder. The has in the first column is the value of HEAD after the action on the right was performed. So you can find the commit hash and checkout the commit you want to return your repo to by checking out its hash

git checkout <commit-hash>

Create a temporary branch off from the commit

git checkout -b new-master

Push it back to the remote repository.

git push -f origin master

However this will have fixed your remote master but note that your local master is still the one you have introduced destructive changes, so you can either delete it with following command if you don't need the changes in it.

git branch -D master , 

or you may need to do something like cherry-pick all the commits that were lost.

PS: You can also find git fsck more suitable for recovering lost commits

链接地址: http://www.djcxy.com/p/3970.html

上一篇: 删除了一个git分支,如何恢复提交?

下一篇: f来源大师'任何方式来恢复?