简体   繁体   English

需要将Git更改推送到另一个分支

[英]Need to push Git changes to another branch

I made a mistake pushing 2 sets of changes to the master branch. 我在将2组更改推送到master分支时犯了一个错误。 But I did not Sync yet (I use Visual Studio). 但是我还没有同步(我使用Visual Studio)。

I've now created a branch off master that I want to move these changes to. 现在,我已经创建了master分支,我希望将这些更改移至其中。 How can I do that? 我怎样才能做到这一点? Either with the git command line or Visual Studio. 使用git命令行或Visual Studio。

The safe and easy approach is to cherry-pick the changes onto the new branch, and then use git revert to create a commit that undoes the changes on the master. 一种安全简便的方法是将更改樱桃选择到新分支上,然后使用git revert创建一个撤消对主服务器上git revert更改的提交。 Don't get involved in editing history unless you absolutely need to, even locally. 除非您绝对需要,否则不要参与编辑历史记录,甚至在本地也是如此。

What you mean by not Sync yet? 您是什么意思还没有同步呢? If you didn't push to the remote yet, you can reset without worries. 如果您尚未推送到遥控器,则可以不用担心reset You said you have created a newly branch just for these changes, so, when creating a branch of your master's HEAD, the changes are already in the newly branch, and just do git checkout master followed by git reset HEAD~2 to erase the last 2 commits. 您说您已经为这些更改创建了一个新分支,因此,在创建主HEAD的分支时,更改已经在新分支中,只需执行git checkout master然后执行git reset HEAD~2来删除最后一个2次提交。

If your branch was already created than move to it and do git cherry pick <hash> , you can get a commit of every branch, just put the referenced hash. 如果已经创建了分支,然后移至该分支并执行git cherry pick <hash> ,则可以提交每个分支的提交,只需放入引用的哈希即可。 You can use git log to get the hash or git reflog if you've for some reason lost some commits. 如果由于某种原因丢失了某些提交,则可以使用git log获取哈希或git reflog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM