Git反转错误

扫码查看

This question already has answers here:
How do I revert a Git repository to a previous commit?

(41个回答)


7年前关闭。




最近,我们项目的一名贡献者提交了一个破坏了我们系统的提交。我正在尝试恢复到最新的工作版本:

我使用git log查找提交:
commit 45359d69e7983946b233d9010f205be19ce8ebfe
Author:Tom
Date:   Mon Apr 14 14:59:50 2014 +0100

    Tweaks the interface to make it more clean

然后,我做:
git checkout 45359d69e7983946b233d9010f205be19ce8ebfe

其次是:
git add -A && git commit -am "revert"

最后,我尝试:
git push

哪个返回:
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'path'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

(在显示路径的地方,我刚刚删除了服务器的网址)

有什么想法吗?

最佳答案

要使用git还原提交,请使用git revert $commit。它将创建具有反向更改的新提交(因此,您将返回到原始版本,而无更改)。

关于Git反转错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23323354/

10-14 17:43
查看更多