美文网首页
代码仓库迁移

代码仓库迁移

作者: osnail | 来源:发表于2018-01-23 15:07 被阅读0次

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、仓库迁移(A仓库代码迁移至B仓库地址,前提A和B的项目名一致)操作步骤:第一步:将A仓库代码clone到本地,...

  • 代码仓库迁移

    Git仓库迁移而不丢失log的方法要求能保留原先的commit记录,应该如何迁移呢?同时,本地已经clone了原仓...

  • Git跨仓库迁移代码文件,并保留git历史记录

    背景: 由于架构优化、组件下沉、仓库调整等原因,在工作中时常需要将仓库A中的代码迁移到仓库B中,同时希望代码迁移后...

  • Git 代码仓库 迁移

    1. 先从原仓库克隆一份裸版本到本地 2. clone下来以后,会得到一个***.git文件夹,点进去 3.在新的...

  • Git代码仓库迁移

    一般来说,有时候我们需要将代码仓库由一个地址放到另外个地址托管。而已有的代码仓库可能会比较庞杂,有大量的本地分支、...

  • 从一个git仓库迁移代码到另一个git仓库(亲测有效版)

    不保留log等提交的记录的迁移就不说了,soeasy!目标:把A仓库的代码迁移到B仓库并且保存所有的git log...

  • git 仓库迁移

    Git仓库使用的过程中,有时候会遇到服务器的迁移,仓库代码不得不从A服务器,迁移到B服务器去,那么怎么迁移而不丢失...

  • Git仓库完整迁移全过程(包含老仓库分支等)

    包括分支以及提交记录数据的迁移。 最近公司的代码仓库由自建的git仓库迁移到了云效,经过多次测试,终于找到了最好的...

  • 工作所遇问题记录

    2017.1.11目的:项目迁移,代码仓库管理用的codding,将项目的代码从一个账号迁移至另一个账号。问题:A...

  • git代码仓库如何迁移?

    从原地址克隆一份裸版本库。语法: 例如: 然后到新的 Git 服务器上创建一个目标项目(准备迁移过去)。比如新项目...

网友评论

      本文标题:代码仓库迁移

      本文链接:https://www.haomeiwen.com/subject/inesaxtx.html