git仓库迁移的解决方案
一、问题
在github中遇到感兴趣的项目,直接克隆下来,随着兴趣越来越浓,在本地做了些修改,后来干脆想fork到自己的github仓库,又要把本地的修改提交到fork后的自己的github仓库中。这时就遇到了git仓库的迁移问题。
二、解决
1. 使用Git命令行操作如下
先查看remote的名字
git branch -r
假设你的remote是origin,用git remote set_url 更换地址
git remote set-url origin remote_git_address
remote_git_address更换成你的新的仓库地址。
2. 使用 IntelliJ IDEA界面化操作,步骤如下:
(1)本地clone自GitHub某开源项目到本地
(2)在本地修改了一些内容
如下,蓝色标题的Java代码即为经过修改的。然后对项目产生兴趣,fork到自己的GitHub仓库中,并想将这些修改提交到自己的GitHub仓库中。




三、参考
Git仓库迁移而不丢失log的方法
- 要求能保留原先的commit记录,应该如何迁移呢?
- 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢?
- 注意:如果使用了代码审核工具Gerrit,那么在进行操作之前需要将Gerrit关掉,等成功恢复后再将Gerrit开户即可
1、使用git push --mirror
先了解一些git的基本参数介绍
git clone --bare
GIT-CLONE(1) Git Manual GIT-CLONE(1)
NAME
git-clone - Clone a repository into a new directory
SYNOPSIS
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--depth <depth>] [--recursive] [--] <repository> [<directory>]
--bare
Make a bare GIT repository. That is, instead of creating <directory> and placing the administrative files
in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there
is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to
corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used,
neither remote-tracking branches nor the related configuration variables are created.
git push --mirror
--mirror
Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited
to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local
refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and
deleted refs will be removed from the remote end. This is the default if the configuration option
remote.<remote>.mirror is set.
1、建立新仓库
- 1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub,或者是本地的私有仓库
git clone --bare git://192.168.10.XX/git_repo/project_name.git
- 2). 然后到新的 Git 服务器上创建一个新项目,比如 GitCafe,亦或是本地的私有仓库,如192.168.20.XX
su - git
cd /path/to/path/
mkdir new_project_name.git
git init --bare new_project_name.git
- 3). 以镜像推送的方式上传代码到 GitCafe 服务器上。
请确保已经添加了公钥到新的机器上
cd project_name.git
git push --mirror git@192.168.20.XX/path/to/path/new_project_name.git
- 4). 删除本地代码
cd ..
rm -rf project_name.git
- 5). 到新服务器上找到 Clone 地址,直接Clone到本地就可以了。
git clone git@192.168.20.XX/path/to/path/new_project_name.git
这种方式可以保留原版本库中的所有内容。
2、切换remote_url
先查看remote的名字
git branch -r
假设你的remote是origin,用git remote set_url 更换地址
git remote set-url origin remote_git_address
remote_git_address更换成你的新的仓库地址。
第二种切换remote_url的方法更直接,直接更改.git/conf配置文件里的ip地址就行。
git仓库迁移的解决方案的更多相关文章
- git仓库迁移的两种解决方案
Git仓库迁移而不丢失log的方法 要求能保留原先的commit记录,应该如何迁移呢? 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢? 注意:如果使用了代码审核工具Gerrit ...
- git仓库迁移和更新远程仓库地址
一.git仓库迁移 1,从原仓库clone或pull到本地仓库 git clone project_name [old_remote_repository_address] 2,在新的git创建一 ...
- git 仓库迁移,git remote 更改源
git仓库迁移 我们有时候需要迁移git仓库,但又想保留每次commit的记录,所以我们只需要更改git remote [源]的问题即可 首先查看你的remote的地址 git remote -vv ...
- git仓库迁移
最近,装了git的本地服务器坏掉了, 没办法只能临时进行仓库的迁移 保证项目正常进行 在项目的根目录执行右键执行 查询当前仓库的远程地址 git remote -v 查看现有远程仓库的地址url 修 ...
- Git仓库迁移命令
1. 从原git上clone bare下到本地 git clone --bare https://***.git 2. push mirror到目标仓库 git push --mirror https ...
- 从一个git仓库迁移到另外一个git仓库
1 从原地址克隆一份裸版本库,比如原本托管于 GitHub. git clone --bare git://github.com/username/project.git git操作的结果会有一个XX ...
- svn迁移到git仓库并保留commit历史记录
svn迁移到git仓库并保留commit历史记录 最近在做svn迁移到gitlab,由于之前一直是由svn做版本控制.最简单的方式是将svn的内容export出来,然后添加到gitlab即可.但是,如 ...
- git知识总结-4.git服务器搭建及迁移git仓库
1. 前言 因为手里有一份代码之前是直接从其它git服务器上克隆下来的,现在想自己搭建一个git服务器把这份代码管起来. 2. 搭建git服务器 1.安装git: $ sudo apt-get ins ...
- svn 版本迁移到 git 仓库
1.拉取 svn代码并转成 git 版本 git svn fetch http://svn.qtz.com/svn/qtz_code/java/qtz_sm/project/qtz_sm -Auser ...
随机推荐
- UVALive - 4126 Password Suspects (AC自动机+状压dp)
给你m个字符串,让你构造一个字符串,包含所有的m个子串,问有多少种构造方法.如果答案不超过42,则按字典序输出所有可行解. 由于m很小,所以可以考虑状压. 首先对全部m个子串构造出AC自动机,每个节点 ...
- java多线程 生产者消费者案例-虚假唤醒
package com.java.juc; public class TestProductAndConsumer { public static void main(String[] args) { ...
- vertex shader must minimally write all four components of POSITION
Though the POSITION semantic must be written out by the vertex shader, it cannot be read in by the p ...
- The Salt Master has rejected this minion's public key!
salt查看日志: salt --log-level=all "10.199.165.244" state.highstate 进入调试模式: salt-minion -l deb ...
- 除了IE浏览器能识别之外,其他浏览器都不能识别的html写法
最近写html页面的时候发现顶部边界margin-top用了定位之后,IE的跟其他浏览器不同,所以用到了把IE跟其他浏览器区分开来的写法 <!--[if !IE]> <div cla ...
- FMDB是iOS平台的SQLite数据库框架
1.FMDB简介 什么是FMDBFMDB是iOS平台的SQLite数据库框架 FMDB以OC的方式封装了SQLite的C语言API 为什么使用FMDB使用起来更加面向对象,省去了很多麻烦.冗余的C语言 ...
- Windows Server 2008 R2换SID要注意
今天刚装Windows2008R2,准备做实验.同样,我对虚拟机采用了母盘和差异磁盘.在新建好的虚拟机上使用NewSID执行更新SID操作时,一切正常,但当更新完并重启进入系统后,竟然蓝屏了. 原 ...
- PAT 垃圾箱分布(30分)dijstra
垃圾箱分布 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 大家倒垃圾的时候,都希望垃圾箱距离自己比较近,但是谁都不愿意守着垃圾 ...
- L2-020. 功夫传人(dfs+vector 或者 邻接矩阵+dij+优先队列)
L2-020. 功夫传人 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一门武功能否传承久远并被发扬光大,是要看缘分的.一般来 ...
- 使用SQL Server保存Session状态,实现单点登录
在做一些应用网站时,我们可能会碰到这样一种情况:整个项目是由多个网站组成的,而我们要实现用户从一个站点登录后,跳转到其他网站不需要重复登录,即实现单点登录.目前实现单点登录的技术也有好几种,这篇文章描 ...