恢复push'd git commit [英] reverting push'd git commit

查看:116
本文介绍了恢复push'd git commit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支 - 主人和开发人员的回购。我正在主分支上工作,并且收到一条消息,表示回购是最新的。我承诺我的更改,并推到远程回购(在github上)。我收到一条消息,说有些更改被拒绝。

然后我做了一个 git pull origin dev ,这显然是错误的做法 - 自合并以来与我的主人开发分支,像一个白痴,我没有注意到这一点,直到我已经推了。所以最后一个提交显示了合并分支'dev'的github.com:myuser/myrepo



我可以得到通过执行 git reset --hard [sha] ,回到我本地回购的最后一个已知良好状态,其中[sha]是合并前的提交(虽然我'我不知道该如何改变原点) - 或者从我读过的内容中,我也可以执行 git revert -m ,然后提交/推送更改。



任何人都可以通过正确的方式来撤消我的合并,并将两个分支恢复到合并之前的位置?



感谢 - 如果有问题,这是一个只有两个开发人员共享的回购协议,所以不会发生重大更改。



编辑以添加:请跟我说话,好像我还是个孩子。我不得不承认,这个Git的东西仍然让我困惑,所以我远离了高级用户!谢谢

解决方案

git reset --hard [sha] 您本地存储库上的分支。要强制这个推送工作,你可以做一个 git push origin + master:master 。 +符号将强制非线性推送工作。



如果其他开发人员已经将错误提交给您,他们将必须执行 git remote update ,然后一个 git reset --hard origin / master (假设它们在主分支上,并且没有做任何其他提交。



请谨慎使用这些命令:-)。祝你好运。


I've got a repo with two branches-- master and dev. I was working on the master branch and pulled, and got a message that the repo was up to date. I committed my changes, and pushed to the remote repo (on github). I got a message saying that some changes were rejected.

I then did a git pull origin dev, which apparently was the wrong thing to do-- since it merged the dev branch with my master, and like an idiot I didn't notice this until I'd already pushed again. So the last commit shows Merge branch 'dev' of github.com:myuser/myrepo.

I can get back to the last known good status on my local repo by doing a git reset --hard [sha], with [sha] being the commit before the merge (though I'm not sure how to then make that change to the origin)-- or from what I've read I can also do a git revert -m and then commit/push that change.

Can anyone walk me through the "right way" to undo my merge, and restore both branches back to where they were prior to the merge?

Thanks-- if it matters this is a shared repo with only two developers, so it's not under heavy changes.

Edit to add: please talk to me as if I were a child. I have to admit this Git stuff still confuses me, so I'm far from a power user! Thanks

解决方案

The git reset --hard [sha] will correct the branch on your local repository. To force this push to work, you can do a git push origin +master:master. The + sign will force the non-linear push to work.

If the other developers have already pulled you wrong commit, they will have to do a git remote update, then a git reset --hard origin/master (provided that they are on their master branch, and have not made any other commits.

Please use these commands with some caution :-). Good luck.

这篇关于恢复push'd git commit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆