如何将一个分支从主分离出来? [英] How does one split a branch from master

查看:115
本文介绍了如何将一个分支从主分离出来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人都称呼,

我的回购存在一些有点奇怪的问题。最初,我只有 master 分支需要提交,但是在完成我的应用程序的功能版本后,我决定创建一个 develop 分支继续开发,但保留工作版本目前(使用 gitk --all )在 master 中保持原样,直到我感觉合并它为止。 c>)我的git日志图如下所示:

 
tag
|
* ---- * ----- * ----- * ----- * ------ * ------ * ------ *主人&develop
\\
-------- * ---- * develop(HEAD)

我不确定自己做了什么,下面是创建 develop 分支的步骤:

  $ git checkout开发
$ vim example.txt
$ git add。
$ git commit -m开发中的第一个文件
$ git push origin develop

在此之后,我开始在开发分支上进行计数,直到我看看 gitk



我想要的(并且认为是正确/健康的方式使用git分支):

 
tag
|
* ---- * ----- * ----- * ----- * ----- * ----- * master
\
* ----- * ----- * develop(HEAD)

我需要做些什么来获得我的回购看起来像上面的图表?



编辑#1:

输出从 git reflog 开发

  54d8daf HEAD @ {0}:重置:移动到HEAD @ {15} 
45dcaa7 HEAD @ {1}:重新绑定完成:返回refs / heads / develop
45dcaa7 HEAD @ {2}:rebase:添加了另一个针对cli参数的健全性检查
f3b0f8b HEAD @ {3}:rebase:我正致力于改进控制台,包括更好的颜色和更多的cammand选项
8c48bab HEAD @ {4}:checkout :从开发移动到8c48babb10ec2f8f28f364ce57b5095cb080c133 ^ 0
54d8daf HEAD @ {5}:结帐:从主计划开发
8c48bab HEAD @ {6}:结帐:从开发移动到主
54d8daf HEAD @ {7 }:rebase:放弃
3bf3f64 HEAD @ {8}:commit:rebase
6aa82d8 HEAD @ {9}:rebase:为cli参数添加另一个完整性检查
a9be651 HEAD @ {10}: rebase:我正致力于改善控制台,包括更好的颜色和更多的cammand选项
8c48bab HEAD @ {11}:checkout:从开发移动到8c48babb10ec2f8f28f364ce57b5095cb080c133 ^ 0
54d8daf HEAD @ {12} :rebase:放弃
7890b76 HEAD @ {13}:rebase:为cli参数添加了另一个完整性检查
46847d7 HEAD @ {14}:rebase:我正致力于改进控制台,包括更好的颜色,以及更多的cammand选项
8c48bab HEAD @ {15}:checkout:从开发移动到8c48babb10ec2f8f28f364ce57b5095cb080c133 ^ 0
54d8daf HEAD @ {16}:commit:改变了how函数,看起来我是对的,wc无论可读符号如何,都计数所有行。
13d35ed HEAD @ {17}:commit:正在处理函数的功能(应该是微不足道的,但我感觉不好)
852fb68 HEAD @ {18}:commit:我添加了一些命令(认为​​没有完全实现),但更具体地说,我改变了匹配
33dfc9f HEAD @ {19}的模式:commit(merge):改变一些输出设置,美学等。我正在努力为列表获得更多的命令选项前面的lin
a248465 HEAD @ {20}:commit(修改):为cli参数添加了另一个完整性检查
f0ca508 HEAD @ {21}:commit(revised) :为cli参数添加了另一个完整性检查
9e24e91 HEAD @ {22}:commit:为cli参数添加了另一个完整性检查
0194cab HEAD @ {23}:commit:我致力于改进控制台,这包括更好的颜色和更多的cammand选项
8c48bab HEAD @ {24}:结帐:从主人移动到测试
8c48bab HEAD @ {25}:commit:我想我已经把所有的导入bug,其余的只是美学,欢迎版本1
b306d9f HEAD @ {26}:commit:事实证明它比较容易,然后我想,再加上我修正了一个不正确的追加方法
8445a25 HEAD @ {27}:commit:似乎我很想理解bash case statments如何处理正则表达式,或者我应该说路径名扩展匹配
9fc5132 HEAD @ {28}:commit:lol,完全忘了使用函数'run'来获取事去
ee2a2c7 HEAD @ {29}:commit:似乎我还没有想出如何正确解析cli args ...
bb0fd28 HEAD @ {30}:commit:修正不正确的完整性检查
eb3db1d HEAD @ {31}:commit:已经到了一个阶段,我可以参考一个正在运行的测试系统,这就是我要做的。
4bfd53b HEAD @ {32}:commit:增加了更多的颜色(正在使用来自拱门维基的列表),包含更好的错误处理
2d9b598 HEAD @ {33}:commit:获得部分1
0edfcae HEAD @ {34}:commit:迄今为止的输出函数
06130a7 HEAD @ {35}:commit:将两个打印函数模块化为单独的脚本
e0033b8 HEAD @ {36}:提交(初始):从以前的bash脚本中使用了一些函数,也许我应该为文本输出创建一个通用脚本......?

错误地,我试图做一次rebase,在每次合并尝试时失败。在 - 他们的 - 我们的中使用 git diff code>)显示远程和本地没有区别。因此,我将头重置为提交 HEAD @ {15}



编辑#2: strong>
对于我可能造成的混淆,我感到抱歉,但是在图1中,'master&开发'表示两个分支( master develop )都合并为一个流。我希望这样做更有意义。



编辑#3:

git log master --pretty = oneline

  8c48babb10ec2f8f28f364ce57b5095cb080c133我想我有剔除了所有的导入bug,其余的只是美观,欢迎版本1 
b306d9f58c3ebab03364c4381754bc87db9e7f2d,因为事实证明它比我想的更容易,再加上我修正了一个不正确的追加方法
8445a258fc388eba5b920de57b1f390623da87a0似乎我想不明白如何bash case stats处理正则表达式,或者我应该说路径名扩展匹配
9fc5132c30bdf2ab143ad046493326ba63e4300d lol,完全忘了使用函数'run'来让事情进行
ee2a2c7ff69498a80e9fc5f36cc340f6e1b95bcb似乎我还没有想出如何正确解析cli args ...
bb0fd28c89a0c16c379774b7fc5768a4160d6852修复不正确的完整性检查
eb3db1d055b45793fb9a3fd5f884926687f7b8dd已经达到了我可以参考的一个阶段国王测试系统,这是我要做的。
4bfd53b3af85d82aea11871a0ddb7f9d583cfb73增加了更多的颜色(我用从拱维基列表),纳入更好的错误处理
2d9b598d77e2b62611dfd2e42b183d0262880014越来越有部分1个
0edfcae88e6eae66de4fae1788433d83b90a1c37输出功能至今
06130a7288ce26b4a2235864f7cd5b48a35dcea6模块化两个打印功能到一个单独的脚本
e0033b8f440f2ffb7b9a120f5a9be9ea167e1e30使用以前的bash脚本的一些功能,也许我应该创建一个通用的脚本文本输出...?

输出为 git log develop --pretty = oneline

  54d8daf475a5e1108cd6345850245db2d0e6fd80更改了how函数,看起来我是对的,wc统计所有行,而不管可读符号是否存在。 
13d35ed979de3518eca26961f3be4bb0b7d8de03我正在研究如何功能(应该是微不足道的,但我有一个不好的感觉)
852fb68b8ca929e1156e38e2a58a12f07bd9aaa5我已经添加了一些更多的命令(思想未完全实现),但更具体地说,我已经改变了pat
33dfc9f187a54dc7234c9ca31bee91eef7c89a98改变一些输出设置,美学等。我正在努力为列表previo
a2484654eff741f4c625f8cb097fbb92f6ac8b9b增加另一个理智检查cli参数
9e24e9157157f128f75b3d7859875d06d33137bd为cli参数增加了另一个理智检查
0194cab8af66656bb9fe83c919409354f6d12edc我正在努力使控制台得到改进,包括更好的颜色和更多的cammand选项
8c48babb10ec2f8f28f364ce57b5095cb080c133我想我已经找到了所有的导入bug,其余的只是美观,欢迎版本1
b306d9f58c3ebab03364c4381754bc87db9e7f2d,因为事实证明它更容易,我想,加上我修正了一个不正确的追加方法
8445a258fc388eba5b920de57b1f390623da87a0似乎我想知道bash case statments如何处理正则表达式,或者我应该说路径名扩展匹配
9fc5132c30bdf2ab143ad046493326ba63e4300d哈哈,完全忘了使用函数'run'来获取东西去
ee2a2c7ff69498a80e9fc5f36cc340f6e1b95bcb似乎我避风港还没有想出如何正确解析cli args ...
bb0fd28c89a0c16c379774b7fc5768a4160d6852修复不正确的完整性检查
eb3db1d055b45793fb9a3fd5f884926687f7b8dd已经达到了一个阶段,我可以参考一个工作测试系统,这是我将要做的。
4bfd53b3af85d82aea11871a0ddb7f9d583cfb73增加了更多的颜色(我用从拱维基列表),纳入更好的错误处理
2d9b598d77e2b62611dfd2e42b183d0262880014越来越有部分1个
0edfcae88e6eae66de4fae1788433d83b90a1c37输出功能至今
06130a7288ce26b4a2235864f7cd5b48a35dcea6模块化两个打印功能到一个单独的脚本
e0033b8f440f2ffb7b9a120f5a9be9ea167e1e30使用以前的bash脚本的一些功能,也许我应该创建一个通用的脚本文本输出...?

输出为 git log master ... develop

 
提交54d8daf475a5e1108cd6345850245db2d0e6fd80
作者:Hans
日期:星期四6月21 21:27:14 2012 +0200

改变了how函数,看起来我是对的,wc统计所有行,不管可读符号与否。

commit 13d35ed979de3518eca26961f3be4bb0b7d8de03
作者:Hans
日期:星期四六月21 21:09:44 2012 +0200

正在研究如何使用函数是微不足道的,但我有一个不好的感觉)

提交852fb68b8ca929e1156e38e2a58a12f07bd9aaa5
作者:Hans
日期:星期四六月21 20:58:16 2012 +0200

我已经添加了一些更多的命令(以为未完全实现),但更具体地说,我已经稍微更改了模式匹配,现在是ar

commit 33dfc9f187a54dc7234c9ca31bee91eef7c89a98
合并:a248465 9e24e91
作者:Hans
日期:星期四六月21 20:42:56 2012 +0200

更改一些输出设置,美学等。我正在努力获得更多的命令选项列表以前的行和这样的

提交a2484654eff741f4c625f8cb097fbb92f6ac8b9b
作者:Hans
日期:星期四6月21日20:23:52 2012 +0200

为cli参数添加了另一项完整性检查

commit 9e24e9157157f128f75b3d7859875d06d33137bd
作者:Hans
日期:星期四6月21日20:23:52 2012 +0200

为cli参数添加了另一项完整性检查

commit 0194cab8af66656bb9fe83c919409354f6d12edc
作者:Hans
日期:星期四6月21日20:06:02 2012 +0200

我正致力于改善控制台,这包括更好的颜色和更多的cammand选项


解决方案根本问题。 然而,正如Alexander指出的那样,有一个 a248465 9e24e91 的异常合并,因此创建了图1中所示的'双提交'。这些提交实际上是相同的提交,但具有不同的SHA1哈希值。我相信这是由于我错误地应用了 git commit --amend



解决方案删除它们是为了重新分发 develop 分支并从历史记录中删除提交 9e24e91



感谢大家的帮助!


Salutations everyone,

I have a somewhat strange problem with my repo. Initial I only had the master branch to commit to, however after I completed a functional version of my application I decided to create a develop branch to continue developing but leave the working version untouched in master until I felt like merging it.

Currently (using gitk --all) my git log graph looks like this:

                             tag 
                              |
*----*-----*-----*-----*------*------*------*         master & develop
                                     \       \
                                      --------*----*  develop (HEAD)

I am unsure as to what I did to cause this, below are the steps I took to creating the develop branch:

$ git checkout develop
$ vim example.txt
$ git add .
$ git commit -m "first file in develop"
$ git push origin develop 

After this I countinued on the develop branch until I took a look at gitk.

What I want (and think to be the correct/health way of using git branches) is:

                            tag
                             |      
*----*-----*-----*-----*-----*-----*               master
                                    \
                                     *-----*-----* develop (HEAD)

What do I need to do to get my repo to look similar to the diagram above?

EDIT #1:

Output from git reflog for develop:

54d8daf HEAD@{0}: reset: moving to HEAD@{15}
45dcaa7 HEAD@{1}: rebase finished: returning to refs/heads/develop
45dcaa7 HEAD@{2}: rebase: added another sanity check for cli parameters
f3b0f8b HEAD@{3}: rebase: I am working on getting the console improved, this including better color, and more cammand options
8c48bab HEAD@{4}: checkout: moving from develop to 8c48babb10ec2f8f28f364ce57b5095cb080c133^0
54d8daf HEAD@{5}: checkout: moving from master to develop
8c48bab HEAD@{6}: checkout: moving from develop to master
54d8daf HEAD@{7}: rebase: aborting
3bf3f64 HEAD@{8}: commit: rebase
6aa82d8 HEAD@{9}: rebase: added another sanity check for cli parameters
a9be651 HEAD@{10}: rebase: I am working on getting the console improved, this including better color, and more cammand options
8c48bab HEAD@{11}: checkout: moving from develop to 8c48babb10ec2f8f28f364ce57b5095cb080c133^0
54d8daf HEAD@{12}: rebase: aborting
7890b76 HEAD@{13}: rebase: added another sanity check for cli parameters
46847d7 HEAD@{14}: rebase: I am working on getting the console improved, this including better color, and more cammand options
8c48bab HEAD@{15}: checkout: moving from develop to 8c48babb10ec2f8f28f364ce57b5095cb080c133^0
54d8daf HEAD@{16}: commit: changed the how function, it seems I was right, wc counts all lines regardless of readable symbols or not.
13d35ed HEAD@{17}: commit: am working on the how function (should be trivial, but I have a bad feeling)
852fb68 HEAD@{18}: commit: I have added some more commands (thought not fully implemented), but more specifically I have changed the pattern matching
33dfc9f HEAD@{19}: commit (merge): change some output settings, asthetics and such. I am working on getting more command options for list previous lin
a248465 HEAD@{20}: commit (amend): added another sanity check for cli parameters
f0ca508 HEAD@{21}: commit (amend): added another sanity check for cli parameters
9e24e91 HEAD@{22}: commit: added another sanity check for cli parameters
0194cab HEAD@{23}: commit: I am working on getting the console improved, this including better color, and more cammand options
8c48bab HEAD@{24}: checkout: moving from master to testing
8c48bab HEAD@{25}: commit: I think I have wroked out all of the import bugs, the rest is really just esthetics, welcome version 1
b306d9f HEAD@{26}: commit: as it turns out it was easier then I thought, plus I fixed an incorrect append method
8445a25 HEAD@{27}: commit: seems I miss understood how bash case statments handles regex, or should I say pathname expansion matching
9fc5132 HEAD@{28}: commit: lol, totally forgot to use the function 'run' to get things going
ee2a2c7 HEAD@{29}: commit: seems I haven't yet figured out how to correctly parse cli args...
bb0fd28 HEAD@{30}: commit: fixed incorrect sanity check
eb3db1d HEAD@{31}: commit: have reached a stage I could refer to a working test system, which is what I am going to do.
4bfd53b HEAD@{32}: commit: added a lot more colours (am using a list from arch-wikis), incorporated much better error handling
2d9b598 HEAD@{33}: commit: getting there part 1
0edfcae HEAD@{34}: commit: output functions so far
06130a7 HEAD@{35}: commit: modularized two printing function into a seperate script
e0033b8 HEAD@{36}: commit (initial): used some functions from previous bash script, maybe I should create a generic script for text output...?

In error, I tried to do a rebase, which failed on every merge attempt. Using git diff on different checkouts of files (--theirs and --ours) showed no difference between remote and local. So I reset head back to commit HEAD@{15}.

EDIT #2: I am sorry for the confusion I might have caused, however in diagram 1, 'master & develop' indicate that both branches (master and develop) are combined into a single 'stream'. I hope that makes more sense.

EDIT #3:

Output from git log master --pretty=oneline

8c48babb10ec2f8f28f364ce57b5095cb080c133 I think I have wroked out all of the import bugs, the rest is really just esthetics, welcome version 1
b306d9f58c3ebab03364c4381754bc87db9e7f2d as it turns out it was easier then I thought, plus I fixed an incorrect append method
8445a258fc388eba5b920de57b1f390623da87a0 seems I miss understood how bash case statments handles regex, or should I say pathname expansion matching
9fc5132c30bdf2ab143ad046493326ba63e4300d lol, totally forgot to use the function 'run' to get things going
ee2a2c7ff69498a80e9fc5f36cc340f6e1b95bcb seems I haven't yet figured out how to correctly parse cli args...
bb0fd28c89a0c16c379774b7fc5768a4160d6852 fixed incorrect sanity check
eb3db1d055b45793fb9a3fd5f884926687f7b8dd have reached a stage I could refer to a working test system, which is what I am going to do.
4bfd53b3af85d82aea11871a0ddb7f9d583cfb73 added a lot more colours (am using a list from arch-wikis), incorporated much better error handling
2d9b598d77e2b62611dfd2e42b183d0262880014 getting there part 1
0edfcae88e6eae66de4fae1788433d83b90a1c37 output functions so far
06130a7288ce26b4a2235864f7cd5b48a35dcea6 modularized two printing function into a seperate script
e0033b8f440f2ffb7b9a120f5a9be9ea167e1e30 used some functions from previous bash script, maybe I should create a generic script for text output...?

Output for git log develop --pretty=oneline

54d8daf475a5e1108cd6345850245db2d0e6fd80 changed the how function, it seems I was right, wc counts all lines regardless of readable symbols or not.
13d35ed979de3518eca26961f3be4bb0b7d8de03 am working on the how function (should be trivial, but I have a bad feeling)
852fb68b8ca929e1156e38e2a58a12f07bd9aaa5 I have added some more commands (thought not fully implemented), but more specifically I have changed the pat
33dfc9f187a54dc7234c9ca31bee91eef7c89a98 change some output settings, asthetics and such. I am working on getting more command options for list previo
a2484654eff741f4c625f8cb097fbb92f6ac8b9b added another sanity check for cli parameters
9e24e9157157f128f75b3d7859875d06d33137bd added another sanity check for cli parameters
0194cab8af66656bb9fe83c919409354f6d12edc I am working on getting the console improved, this including better color, and more cammand options
8c48babb10ec2f8f28f364ce57b5095cb080c133 I think I have wroked out all of the import bugs, the rest is really just esthetics, welcome version 1
b306d9f58c3ebab03364c4381754bc87db9e7f2d as it turns out it was easier then I thought, plus I fixed an incorrect append method
8445a258fc388eba5b920de57b1f390623da87a0 seems I miss understood how bash case statments handles regex, or should I say pathname expansion matching
9fc5132c30bdf2ab143ad046493326ba63e4300d lol, totally forgot to use the function 'run' to get things going
ee2a2c7ff69498a80e9fc5f36cc340f6e1b95bcb seems I haven't yet figured out how to correctly parse cli args...
bb0fd28c89a0c16c379774b7fc5768a4160d6852 fixed incorrect sanity check
eb3db1d055b45793fb9a3fd5f884926687f7b8dd have reached a stage I could refer to a working test system, which is what I am going to do.
4bfd53b3af85d82aea11871a0ddb7f9d583cfb73 added a lot more colours (am using a list from arch-wikis), incorporated much better error handling
2d9b598d77e2b62611dfd2e42b183d0262880014 getting there part 1
0edfcae88e6eae66de4fae1788433d83b90a1c37 output functions so far
06130a7288ce26b4a2235864f7cd5b48a35dcea6 modularized two printing function into a seperate script
e0033b8f440f2ffb7b9a120f5a9be9ea167e1e30 used some functions from previous bash script, maybe I should create a generic script for text output...?

Output for git log master...develop

commit 54d8daf475a5e1108cd6345850245db2d0e6fd80
Author: Hans 
Date:   Thu Jun 21 21:27:14 2012 +0200

    changed the how function, it seems I was right, wc counts all lines regardless of readable symbols or not.

commit 13d35ed979de3518eca26961f3be4bb0b7d8de03
Author: Hans 
Date:   Thu Jun 21 21:09:44 2012 +0200

    am working on the how function (should be trivial, but I have a bad feeling)

commit 852fb68b8ca929e1156e38e2a58a12f07bd9aaa5
Author: Hans 
Date:   Thu Jun 21 20:58:16 2012 +0200

    I have added some more commands (thought not fully implemented), but more specifically I have changed the pattern matching slightly, it is now a r

commit 33dfc9f187a54dc7234c9ca31bee91eef7c89a98
Merge: a248465 9e24e91
Author: Hans 
Date:   Thu Jun 21 20:42:56 2012 +0200

    change some output settings, asthetics and such. I am working on getting more command options for list previous lines and such

commit a2484654eff741f4c625f8cb097fbb92f6ac8b9b
Author: Hans 
Date:   Thu Jun 21 20:23:52 2012 +0200

    added another sanity check for cli parameters

commit 9e24e9157157f128f75b3d7859875d06d33137bd
Author: Hans 
Date:   Thu Jun 21 20:23:52 2012 +0200

    added another sanity check for cli parameters

commit 0194cab8af66656bb9fe83c919409354f6d12edc
Author: Hans 
Date:   Thu Jun 21 20:06:02 2012 +0200

    I am working on getting the console improved, this including better color, and more cammand options

解决方案

As it turns out, I misunderstood how branches work in git. This was the fundamental problem. There was no problem at all with how my repo is setup.

However as Alexander pointed out to me, there is an abnormal merge of a248465 9e24e91, thus creating this 'double commit' shown in diagram 1. These commits are actually the same commit but with different SHA1 hashes. I believe this was caused to due to me having incorrectly applied a git commit --amend.

The solution to remove them was to rebase the develop branch and remove commit 9e24e91 from the history.

Thanks everyone for your help!

这篇关于如何将一个分支从主分离出来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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