git reset退回指定版本后,怎么提交上服务器?

【字号: 日期:2023-08-23浏览:34作者:雯心

问题描述

情况是这样的:

今天发现稍早的一次提交,刚刚发现有些文件被删除了。

现在要退回指定的版本commit:20a3725c

git reset --hard 20a3725c

然后重新git push时失败,提示:

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 behindhint: 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.

现在需要恢复到版本20a3725c,应该怎么解决呢?

还有一个问题就是能够将原本删除的文件,恢复到当前版本吗?(因为当前版本有增减某些文件(在其它文件夹,不与被删文件同一文件夹))

问题解答

回答1:

还没有想到办法解决。

(先备份当前有修改过的文件)

最好,先返回指定版本git reset old_commit_id

然后,新建分支 git branch -b rcommit_id

再,删除线上的master分支(将默认分支切换到其它分支)git push origin :master

然后,将之前备份的文件覆盖当前分支内的文件。最后,将分支名改为master,再提交即可,再设置为默认分支。

git branch -m rcommit_id mastergit push origin master回答2:

必须要修改下才可以推送。。。如果你只是要恢复某个版本,可以使用git revert来把那个提交取消掉

回答3:

git revert ’20a3725cgit push

相关文章: