简体   繁体   English

将git用于两个分支

[英]Use git for two branch

think I am going to use these three files in Master Branch 认为我将在Master Branch中使用这三个文件

MASTER : 主:

index.php

  <b>hello</b>

test.php
img.jpeg

now I create a branch from Master 现在我从师父创建一个分支

NewBranch : NewBranch:

index.php

     <b>hello</b>

test.php
img.jpeg

and now I will edit Master index.php file, and I will add two lines of code to master branch 现在我将编辑Master index.php文件,并将两行代码添加到master分支

MASTER : 主:

index.php

  <b>hello</b>
  <a>test</a>
  <p>good</p>     

and I will change some code in NewBranch 我将在NewBranch中更改一些代码

NewBranch : NewBranch:

index.php

     <b>hello</b>
     <div>this is new branch line</div> 

I want to update NewBranch so I will have my own edited lines on New Branch and also updated lines on Master Branch 我想更新NewBranch,所以我将在New Branch上有自己的编辑行,并且在Master Branch上也有更新的行

NewBranch : (should be like as below) NewBranch :(应如下所示)

index.php

     <b>hello</b>
     <div>this is new branch line</div>
     <a>test</a>
     <p>good</p>  

How can I achieve that? 我该如何实现? I have used netbeans Pull and Fetch, but did not worked. 我使用过netbeans Pull and Fetch,但没有用。 I also do not want to use git submodule ( as I do not have separate folder ) 我也不想使用git子模块(因为我没有单独的文件夹)

  1. You changes on both the branches should be "committed". 您在两个分支上的更改都应该“提交”。 Only changing will do no good. 仅改变将无济于事。
  2. Then you can rebase your NewBranch over master ( git rebase master NewBranch ) 然后您可以通过master重新设置NewBranch的基础( git rebase master NewBranch
  3. Now you new branch has changes of itself and that of master. 现在,您的新分支具有自身和主分支的更改。 But master will have only its changes. 但是主人只会有它的改变。

For more details on rebase please refer this . 有关rebase的更多详细信息,请参阅

These are the steps (assuming that you are using gitBash): 这些是步骤(假设您正在使用gitBash):

git checkout newbranch

do the changes for newbranch git commit -a -m "Your message" 为newbranch进行更改git commit -a -m“您的消息”

git checkout master

do the changes for master 为主人做改变

git commit -a -m "Your message"

now merging 现在正在合并

git checkout newbranch
git merge master
git push
git checkout master
git merge newbranch
git push
gitk //you should see that both are at the same level in the git tree

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

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