我团队中的某个人不小心向 GIT 推送了一个任何人都不应该拉取的提交(因为它包含许多更改并且基本上破坏了我们所拥有的一切)。
他试图恢复到另一个版本,但得到了一个错误。
所以基本上,他整天都在处理他的本地副本。没有人从存储库中推送或拉取。
我们想要做的是以某种方式保留他的本地更改,但删除他推送的内容。
我们怎样才能做到这一点?
谢谢你。
git push --force
将强制推送您的本地分支,即使远程存储库上有新的提交。
您要么想要将本地 git repo 重置为预推送状态并将其推送到远程源,要么如果您有权访问您的 git 服务器,只需直接将其还原。
本地机器:
1. git log
get the commit id for the last usable commit
2. git reset --hard <commit id>
replace <commit id> with the id you retrieved in step 1
3. git push -f origin <branch name>
在 git 服务器上:
1. git log
get the commit id for the last usable commit
2. git reset --hard <commit id>
replace <commit id> with the id you retrieved in step 1
一旦错误的提交消失,只需像往常一样推送新的更改。
这是一个常见的问题。以前已针对此类事情发布了修复程序。请务必在询问之前搜索,可能会节省一些时间!