search

Home  >  Q&A  >  body text

After git reset returns the specified version, how to submit it to the server?

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))

阿神阿神2755 days ago994

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味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 first
    git 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

    reply
    0
  • 高洛峰

    高洛峰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

    reply
    0
  • 为情所困

    为情所困2017-06-05 11:10:52

    git revert '20a3725c
    git push

    reply
    0
  • Cancelreply