如何合并两个Git仓库
欢迎和大家交流技术相关问题:
邮箱: jiangxinnju@163.com
博客园地址: http://www.cnblogs.com/jiangxinnju
GitHub地址: https://github.com/jiangxincode
知乎地址: https://www.zhihu.com/people/jiangxinnju
假设有两个Git仓库:
- github: https://github.com/jiangxincode/thesis.git
- bitbucket: https://jiangxincode@bitbucket.org/jiangxincode/thesis.git
现在需要进行合并,保留双方的历史提交记录,并将github的内容删除,合并之后的内容推送到bitbucket中。
从Github上clone仓库到github目录:
$ git clone https://github.com/jiangxincode/thesis.git github
Cloning into 'github'...
remote: Enumerating objects: 29, done.
remote: Total 29 (delta 0), reused 0 (delta 0), pack-reused 29
Unpacking objects: 100% (29/29), done.
从Bitbucket上clone仓库到bitbucket目录:
$ git clone https://jiangxincode@bitbucket.org/jiangxincode/thesis.git bitbucket
Cloning into 'bitbucket'...
remote: Counting objects: 153, done.
remote: Compressing objects: 100% (150/150), done.
remote: Total 153 (delta 63), reused 0 (delta 0)
Receiving objects: 100% (153/153), 26.68 MiB | 2.64 MiB/s, done.
Resolving deltas: 100% (63/63), done.
在合并前根据实际需要分别处理两个目录的内容,并提交上传到远程仓库。
在仓库bitbucket中添加远程仓库github,命名为github:
$ cd bitbucket/
$ git remote add github ../github/
$ git remote
github
origin
检出历史信息:
$ git fetch github
warning: no common commits
remote: Enumerating objects: 32, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 32 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (32/32), done.
From ../github
* [new branch] master -> github/master
基于github的master分支创建并检出新的分支,名字为github_master:
$ git checkout -b github_master github/master
Switched to a new branch 'github_master'
Branch 'github_master' set up to track remote branch 'master' from 'github'.
切到bitbucket仓库的主线分支:
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
合并基于github创建的分支github_master到仓库bitbucket的master分支上:
$ git merge github_master --allow-unrelated-histories
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.
此处可以看出出现了冲突,需要先解决冲突:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Changes to be committed:
new file: tex-source/LICENSE
new file: tex-source/Makefile
new file: tex-source/abstract.tex
new file: tex-source/dtx-style.sty
new file: tex-source/englishabstract.tex
new file: tex-source/gbt7714-2005.bst
new file: tex-source/get_texmf_dir.sh
new file: tex-source/jiangxin.bib
new file: tex-source/jiangxin.tex
new file: tex-source/njulogo.eps
new file: tex-source/njuname.eps
new file: tex-source/njuthesis.cfg
new file: tex-source/njuthesis.cls
new file: tex-source/njuthesis.dtx
new file: tex-source/njuthesis.ins
new file: tex-source/preface.tex
Unmerged paths:
(use "git add <file>..." to mark resolution)
both added: .gitignore
$ git add .gitignore
$ git commit
[master 3d6cb22] Merge branch 'github_master'
最后push本地所有分支到bitbucket:
$ git push origin master
Enumerating objects: 37, done.
Counting objects: 100% (37/37), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (35/35), 320.42 KiB | 3.56 MiB/s, done.
Total 35 (delta 9), reused 0 (delta 0)
To https://bitbucket.org/jiangxincode/thesis.git
f92ef9e..3d6cb22 master -> master
$ git push origin github_master:github_master
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create pull request for github_master:
remote: https://bitbucket.org/jiangxincode/thesis/pull-requests/new?source=github_master&t=1
remote:
To https://bitbucket.org/jiangxincode/thesis.git
* [new branch] github_master -> github_master
此时查看本地和远程的所有分支:
$ git branch -a
github_master
* master
remotes/github/master
remotes/origin/HEAD -> origin/master
remotes/origin/github_master
remotes/origin/master
origin/master
如何合并两个Git仓库的更多相关文章
- 合并两个git仓库
现有两个git仓库ekt_zy.ekt_zijian,需要把ekt_zijian项目中的代码合并到ekt_zy项目中. 1 将ekt_zijian作为远程仓库.添加到ekt_zy中,设置别名为ziji ...
- 合并两个git仓库并保留提交记录
case如下: 有2个git仓库:repo1.repo2: 想将repo1中的文件移入repo2: repo1的历史日志要保留: 1 2 # 1.将repo1作为远程仓库,添加到repo2中,设置 ...
- git push如何至两个git仓库
分别有仓库 A(github),B(JAE 的 git),本机为C. 假设以 a 仓库作为最终的使用仓库, b为发布仓库.分支都为 dev 第一步,增加远程仓库 git remote add orig ...
- 如何合并两个git commit
把你的修改stage之后运行: git rebase -i HEAD~2 然后把第二行的pick改成squash就ok啦 note: 同理,如果要合并多个commit,把后面的2改成你想要合并的com ...
- 多本地代码工作点更新到2个远端GIT仓库
摘要:本文介绍了笔者多个本地工作节点(地方)的多台电脑(PC/笔记本电脑)同步源码到2个远端的GIT(一个GITHUB国外强制公开,一个oschina国内可不公开). 作者:太初 转载说明:请指明原作 ...
- git 合并两个仓库
我有两个仓库,一个是gitbook在写一本 一个是放在github的垃圾,这个是我想要开个人网站,但是做的还是不行https://github.com/lindexi/lindexi.github.i ...
- Git 合并两个不同的仓库
目录 第一步. 下载需要合并的分支 第二步. 添加需要合并远程仓库 第三步. 把base远程仓库中数据抓取到本仓库 第四步. checkount切换到base分支上,命名为 asf 第五步. 合并 总 ...
- commit日志历史不一致的Git仓库合并
有个项目,用SVN commit的在国内开源中国的码云托管,可以直接Git clone"导出"一个本地的git仓库,我在Github上新建立了一个远程的仓库,准备把在码云上clon ...
- GIT 如何合并另一个远程Git仓库的文件到本地仓库里某个指定子文件夹并不丢失远程提交记录?
问题背景: 最近在重新整理手中的一个项目,目前该项目分为PC项目,手机项目,某第三方接口项目,第三方接口服务项目和手机项目 因为之前规划的原因,原来的四个项目是分两个解决方案来管理的 ...
随机推荐
- spring boot 部署
指定运行的内存 java -Xms10m -Xmx200m -jar xxx.jar spring boot 打包成war包: 让 SpringbootApplication 类继承 SpringBo ...
- TOP100summit 2017:亚马逊Echo音箱能够语音识人,华人工程师揭秘设计原理
本文编辑:Cynthia 2017年,人工智能的消费产品落地聚焦在了智能音箱上,谷歌.亚马逊纷纷推出智能音箱产品,国内的阿里巴巴推出天猫精灵,小米推出小米AI音箱.智能音箱通过语音可以发出指令,未 ...
- sftp本地上传和远程下载
1. 打开SecureCRT 连接相应的主机 2. 打开会话后,使用快捷键 alt + p,进入 sftp> 界面 3. 查看 sftp 相应的命令 help 4. 常用命令 (1)查看 ...
- C# 多线程 详解
[基础篇] 怎样创建一个线程 受托管的线程与Windows线程 前台线程与后台线程 名为BeginXXX和EndXXX的方法是做什么用的 异步和多线程有什么关联 [WinForm多线程编程篇] 多线程 ...
- maven配置(myeclipse版)
使用环境说明: OS:windows 7 64位 java version: "jdk1.8.0_66" IDE:myeclipse 2017 1.下载 下载地址:http://m ...
- PHP AOP编程思想
AOP思想(面向切面编程) 在应用开发中,我们经常发现需要很多功能,这些功能需要经常被分散在代码中的多个点上,但是这些点事实上跟实际业务没有任何关联.比如,在执行一些特殊任务之前需要确保用户是在登陆状 ...
- Balls and Boxes---hdu5810(推公式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5810 有n个球m个盒子,随机把球放到盒子中,求每个盒子球个数的方差的期望值 E[V]; 推公式吧,或者 ...
- 洛谷P3966 单词 [TJOI2013] AC自动机
正解:AC自动机 解题报告: 传送门! 先来提供一个40pts错解QAQ 首先看到这题就会想到AC自动机板子题2鸭!然后就照着那题的套路打一下,随便改一点儿,简单来说就是每次经过一个节点都要++,然后 ...
- 洛谷P2444 病毒 [POI2000] AC自动机
正解:AC自动机 解题报告: 传送门! 首先看到这种题目二话不说先把trie树和fail指针建立起来 然后就想鸭,如果我们想让模式串和文本串尽量不能匹配,就要想办法让它跳fail指针,而不是继续往下走 ...
- GDB调试qemu源码纪录
今天介绍下如何利用gdb调试qemu 1.首先获取qemu源码 获取地址:https://www.qemu.org/ 2.编译安装qemu 进入qemu目录 ./configure --enable- ...