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仓库迁移的两种解决方案的更多相关文章

  1. git仓库迁移的解决方案

    一.问题 在github中遇到感兴趣的项目,直接克隆下来,随着兴趣越来越浓,在本地做了些修改,后来干脆想fork到自己的github仓库,又要把本地的修改提交到fork后的自己的github仓库中.这 ...

  2. git仓库迁移和更新远程仓库地址

    一.git仓库迁移 1,从原仓库clone或pull到本地仓库 git clone project_name ​[old_remote_repository_address] 2,​在新的git创建一 ...

  3. PHP中实现MySQL嵌套事务的两种解决方案

    PHP中实现MySQL嵌套事务的两种解决方案 一.问题起源 在MySQL的官方文档中有明确的说明不支持嵌套事务: Transactions cannot be nested. This is a co ...

  4. javascript文件夹选择框的两种解决方案

    javascript文件夹选择框的两种解决方案 解决方案1:调用windows 的shell,但会有安全问题. * browseFolder.js * 该文件定义了BrowseFolder()函数,它 ...

  5. git 仓库迁移,git remote 更改源

    git仓库迁移 我们有时候需要迁移git仓库,但又想保留每次commit的记录,所以我们只需要更改git remote [源]的问题即可 首先查看你的remote的地址 git remote -vv ...

  6. Android 的保活的两种解决方案

    原文链接:http://blog.csdn.net/pan861190079/article/details/72773549 详细的阐述了 Android 的保活的两种解决方案 —— 由panhao ...

  7. Idea中Git的使用和两种类型的冲突解决

    一.Git冲突解决 在idea开发工具中使用Git时,主要用到的快捷按钮如下五个:   这五个按钮的使用说明及在idea中如何配置和使用git可参考https://github.com/DayThin ...

  8. 转:前端页面a标签嵌套a标签效果的两种解决方案

      这是由工作中的一个小改动需求得到的这个解决方案的:那个需求是这样的,如图: 需求原来是球队名字没有点击功能的,而蓝色方框两队之间的比赛点击的时候会跳转到比赛文字直播页面.现在需要要求点击球队名字要 ...

  9. 前端页面a标签嵌套a标签效果的两种解决方案

    这是由工作中的一个小改动需求得到的这个解决方案的:那个需求是这样的,如图: 需求原来是球队名字没有点击功能的,而蓝色方框两队之间的比赛点击的时候会跳转到比赛文字直播页面.现在需要要求点击球队名字要跳转 ...

随机推荐

  1. 【BZOJ1879】[Sdoi2009]Bill的挑战 状压DP

    [BZOJ1879][Sdoi2009]Bill的挑战 Description Input 本题包含多组数据.  第一行:一个整数T,表示数据的个数.  对于每组数据:  第一行:两个整数,N和K(含 ...

  2. interface Impl

    public interface ActionBarOperations { void initSthOne(); void initSthTwo(); } public class ActionBa ...

  3. LOL TGP更新影响VS debug 问题

    刚才看群里说到VS无法调试,出现"无法使用xxx附加到应用程序'webdev.webserver...'"的问题,群友提出自己的经历,可能是LOL TGP的问题. 提问者卸载了TG ...

  4. Iframe中子窗体给父窗体传值

    <html> <head> <script type="text/javascript"> function GetData(data) { a ...

  5. Python开发【模块】:matplotlib 绘制折线图

    matplotlib 1.安装matplotlib ① linux系统安装 # 安装matplotlib模块 $ sudo apt-get install python3-matplotlib # 如 ...

  6. Python开发【Django】:分页、Cookie和Session

    分页 1.简单分页 涉及xss攻击,需要用到mark_safe方法,使用此方法字符串传输到后端后,已html形式显示,而非字符串 HTML文件: <!DOCTYPE html> <h ...

  7. Spring boot maven 搭建框架

    Spring Boot:目的:这个框架帮助开发者更容易地创建基于Spring的应用程序和服务,使得pring开发者能够最快速地获得所需要的Spring功能.优点:完全不需要XML配置,让spring应 ...

  8. 流畅的python 读书笔记 第二章 序列构成的数组 列表推导

    列表推导是构建列表(list)的快捷方式,而生成器表达式则可以用来创建其他任何类型的序列.如果你的代码里并不经常使用它们,那么很可能你错过了许多写出可读性更好且更高效的代码的机会. 2.2.1 列表推 ...

  9. java-mybaits-00801-逆向工程

    1.1     什么是逆向工程 参看地址:http://www.mybatis.org/generator/index.html 使用官方网站的mapper自动生成工具mybatis-generato ...

  10. nodejs Async详解之二:工具类

    Async中提供了几个工具类,给我们提供一些小便利: memoize unmemoize log dir noConflict 1. memoize(fn, [hasher]) 有一些方法比较耗时,且 ...