Git推到错误的分支 [英] Git push to wrong branch

查看:461
本文介绍了Git推到错误的分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用git,经过一些提交和一些推送之后,我意识到正在使用错误的分支!

Working with git, after some 'commit', and a couple of 'push', I realized that am using the wrong branch !

现在我必须删除在某种程度上,我更改了wrong_branch
,并提交并推送了right_branch中的更改。

Now I have to remove in some way my changes in wrong_branch and commit and push the changes in right_branch

什么是最好的(也是最简单的)方法呢?

What's the best (and simple) way to do that ?

谢谢

推荐答案

切换到该分支,检查 git log git revert 单独提交这些提交。完成之后,切换回所需的分支,然后您可以使用 git cherry-pick 从git refs中选择特定的提交并将其合并到右边的分支

switch to that branch, check the git log and git revert those commits individually. Once you have done that, switch back to the desired branch and there you can then use git cherry-pick to pick specific commits from the git refs and merge it into the right branch.

git checkout wrong_branch
git revert commitsha1
git revert commitsha2
git checkout right_branch
git cherry-pick commitsha1
git cherry-pick commitsha2

如果提交是分组在一起,在你的提交之后没有提交任何提交,甚至可以使用 git reset 将错误的分支转移到提交之前的状态,然后再次使用 git cherry-pick 让您的提交进入正确的分支。

If the commits are grouped together and there are no commits pushed after your dirty commits, you can even use git reset to get that wrong branch to a state just before your commits and then follow that again using git cherry-pick to get your commits into the right branch.

git checkout wrong_branch
git reset commitsha3 #commit just before commitsha2
git checkout right_branch
git cherry-pick commitsha1
git cherry-pick commitsha2

这篇关于Git推到错误的分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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