The situation is like this:
I found an earlier submission today and just found that some files were deleted.
Now we want to return to the specified version commit:20a3725c
git reset --hard 20a3725c
Then re-git push
failed, prompt:
To git@xxx/xxx.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@xxx/xxx.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Now we need to restore to version 20a3725c
, how to solve it?
Another question is, can the originally deleted files be restored to the current version? (Because the current version has added or deleted some files (in other folders, not the same folder as the deleted files))
淡淡烟草味2017-06-05 11:10:52
I haven’t thought of a solution yet.
(Back up the currently modified files first)
Best, return to the specified version firstgit reset old_commit_id
Then, create a new branch git branch -b rcommit_id
Next, delete the online master
branch (switch the default branch to another branch) git push origin:master
Then, overwrite the files in the current branch with the previously backed up files.
Finally, change the branch name to master
, submit it again, and then set it as the default branch.
git branch -m rcommit_id master
git push origin master
高洛峰2017-06-05 11:10:52
It must be modified before it can be pushed. . .
If you just want to restore a certain version, you can use git revert to cancel that commit