[英]Accidentally branched from a topic branch instead of master
I'm working on multiple topic branches. 我正在多个主题分支上。 One topic branch has a lot of new features and is 17 commits ahead of master.
一个主题分支具有许多新功能,并且比master分支提前17次提交。
Now I decided to work on another topic, and branched off to a new topic. 现在,我决定研究另一个主题,然后分支到一个新主题。 I made a commit and this single commit is ready for a pull request on GitHub.
我进行了提交,并且该单个提交已准备好在GitHub上进行拉取请求。 However I noticed that I accidentally branched off my previous topic branch instead of master, so GitHub is previewing me with the other 17 commits of the other topic branch.
但是我注意到我不小心分支了我以前的主题分支而不是master,所以GitHub用另一个主题分支的其他17个提交预览了我。 How do I move this new commit to a topic branch which doesn't have the commits of the previous topic branch?
如何将此新提交移至没有上一个主题分支的提交的主题分支?
Well the problem is that it is not said that this will be straight forward, since perhaps you have changed files that were already changed by your previous file. 很好的问题是,这并不是说这很简单,因为也许您已更改了先前文件已更改的文件。 In case the changes are thus dependent , then you will have to resolve conflicts.
如果更改因此是从属的 ,那么您将必须解决冲突。
Nevertheless you can do the following: 不过,您可以执行以下操作:
git checkout master
git checkout master
git checkout -b new_topic_branch
git checkout -b new_topic_branch
git cherry-pick A..B
with A
the hash of the first commit of the "accidental" branch, and B
the last commit of that branch). git cherry-pick A..B
选择这些提交,其中A
是“偶然”分支的第一次提交的哈希,而B
是该分支的最后一次提交的哈希)。 In this particular case you seem to have made only one commit, so you can git cherry-pick commit
with commit
the hash of that single commit git cherry-pick commit
并commit
该单个提交的哈希 Optionally you can then merge that branch into the master. 您也可以选择将该分支合并到主分支中。
Perhaps the conceptually easiest and cleanest way to handle this situation would be to create a new topic branch from the latest master
, and then cherry-pick your single commit onto it: 解决这种情况的概念上最简单,最简洁的方法可能是从最新的
master
创建一个新的主题分支,然后将您的单个提交樱桃挑选:
First find the SHA-1 hash of the latest commit on your old topic branch: 首先在您的旧主题分支上找到最新提交的SHA-1哈希:
git checkout old_topic
git log
The first entry is the latest commit which you had intended to be in its own branch. 第一个条目是您打算在其自己的分支中执行的最新提交。 Record the SHA-1 hash of this commit (the first 8 characters should be enough).
记录此提交的SHA-1哈希(前8个字符应足够)。
Now create a new topic branch from master
and cherry-pick the commit you want: 现在,从
master
创建一个新的主题分支,然后选择所需的提交:
git checkout master
git pull origin master
git checkout -b new_topic
Now cherry pick the commit 现在樱桃选择提交
git cherry-pick SHA-1
Just rebase the new branch onto master: 只需将新分支重新建立到master上即可:
git checkout new-topic
git rebase --onto master old-topic
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.