在工作中,我需要将一个项目的fork中的Branch,上传到另一个fork当中,然后再将这个Branch和另一个Branch进行合并:
以下是我的操作过程:
首先clone ForkB:
git clone https://github.com/ronsigal/Resteasy.git
然后在clone下来的工程里添加ForkA的地址:
git remote add dst_fork [email protected]:liweinan/Resteasy.git
注意上面添加的是可读写的地址。然后我将想要上传的Branch给push到ForkA:
git push dst_fork RESTEASY_1_2_1_637_647
执行结果如下:
Counting objects: 277, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (96/96), done.
Writing objects: 100% (218/218), 40.87 KiB, done.
Total 218 (delta 63), reused 197 (delta 53)
To [email protected]:liweinan/Resteasy.git
* [new branch] RESTEASY_1_2_1_637_647 -> RESTEASY_1_2_1_637_647
接下要做的是在ForkA里面合并两个Branch。首先将ForkA给clone到本地:
git clone [email protected]:liweinan/Resteasy.git
然后签出待合并分支:
git checkout RESTEASY_JAXRS_1_2_1_GA_CP03
因为不想在这个分支内做全并,因此在合并分支之前。基于这个Branch做一个新的Branch:
git checkout -b RESTEASY_JAXRS_1_2_1_GA_CP04
查看此时所处分支:
git branch
* RESTEASY_JAXRS_1_2_1_GA_CP04
查找一下待合并的分支:
git show-branch -a | grep RESTEASY_1_2_1_637_647
查找结果如下:
! [origin/RESTEASY_1_2_1_637_647] RESTEASY-668
+ [origin/RESTEASY_1_2_1_637_647] RESTEASY-668
+ [origin/RESTEASY_1_2_1_637_647^] RESTEASY-659
+ [origin/RESTEASY_1_2_1_637_647~2] RESTEASY-659: Added isExpandEntityReferences().
+ [origin/RESTEASY_1_2_1_637_647~3] RESTEASY-659: Added providers and unit tests.
+ [origin/RESTEASY_1_2_1_637_647~4] RESTEASY-637, RESTEASY-647
+ [origin/RESTEASY_1_2_1_637_647~5] RESTEASY-637, RESTEASY-647: change two poms.
+ [origin/RESTEASY_1_2_1_637_647~6] RESTEASY-637, RESTEASY-647
+ [origin/RESTEASY_1_2_1_637_647~7] release
注意到分支在origin里面。最后进行合并:
git merge origin/RESTEASY_1_2_1_637_647
合并结果如下:
CONFLICT (delete/modify): examples/oreilly-workbook/ex09_1/pom.xml deleted in HEAD and modified in origin/RESTEASY_1_2_1_637_647. Version origin/RESTEASY_1_2_1_637_647 of examples/oreilly-workbook/ex09_1/pom.xml left in tree.
CONFLICT (delete/modify): examples/oreilly-workbook/ex09_2/pom.xml deleted in HEAD and modified in origin/RESTEASY_1_2_1_637_647. Version origin/RESTEASY_1_2_1_637_647 of examples/oreilly-workbook/ex09_2/pom.xml left in tree.
CONFLICT (delete/modify): examples/oreilly-workbook/ex10_1/pom.xml deleted in HEAD and modified in origin/RESTEASY_1_2_1_637_647. Version origin/RESTEASY_1_2_1_637_647 of examples/oreilly-workbook/ex10_1/pom.xml left in tree.
Auto-merging providers/jaxb/pom.xml
Auto-merging war-tests/encoding-test/pom.xml
Automatic merge failed; fix conflicts and then commit the result.
git像上面这样给出了Conflicts信息。根据实际情况解决冲突后即可提交。