简体   繁体   English

意外地从主题分支而非主分支

[英]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: 不过,您可以执行以下操作:

  1. go to the master git checkout master 转到主git checkout master
  2. create a topic branch (another name than the "accidental" topic branch): git checkout -b new_topic_branch 创建一个主题分支(“偶然”主题分支以外的另一个名称): git checkout -b new_topic_branch
  3. inspect your git tree and take a look at the commit hashes (the first and the last of the "accidental" branch). 检查您的git树,并查看提交哈希(“意外”分支的第一个和最后一个)。
  4. cherry pick these commits with 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). cherry用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 commitcommit该单个提交的哈希
  5. if that succeeds, than the last changes are also processed on the new branch. 如果成功,那么最后的更改也会在新分支上处理。

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.

相关问题 我没有从分支机构分支,而是从分支机构分支 - I didnt branch off of master, instead branched off of a branch 从功能分支而不是开发分支 - Branched from feature branch instead of develop 意外地分支了错误的分支,当我想合并到主服务器时,我必须合并两个分支 - Accidentally branched off of the wrong branch, and when I want to merge into the master I have to merge both branches jenkins将多个分支合并到从master分支的“ integration-branch” - jenkins merge multiple branches to “integration-branch” branched from master 从master检出新分支,并从另一个分支(从master分支出来)进行更改? - Check out new branch from master with changes from another branch, which is branched out from master? pull而不是fetch - 意外地将远程master合并到本地分支 - pull instead of fetch - accidentally merged remote master into local branch git:我不小心将功能分支合并到master中,而不是进行合并 - git: I accidentally merged feature branch into master instead of develop git 问题:继续将主分支更改拉入从功能分支分支出来的单个开发分支是否更好? - git question : is it better to keep pulling master branch changes into individual dev branch branched out from a feature branch? 在已经分支的分支上进行 master rebase 后的问题 - Issue after master rebase on a branch that was already branched 是从本身从 master 分支的 branchA 分支,与从 master 分支相同,然后从 master 的另一个分支合并更改吗? - Is branching from branchA which itself branched from master, same as branching from master, and then merging changes from another branch of master?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM