当前位置:   article > 正文

git push –mirror 迁移 Git 项目 ~转_git push --mirror

git push --mirror

 git push –mirror 迁移 Git 项目

git仓库迁移的两种解决方案

Git仓库迁移而不丢失log的方法

  • 要求能保留原先的commit记录,应该如何迁移呢?
  • 同时,本地已经clone了原仓库,要配置成新的仓库地址,该如何修改呢?
  • 注意:如果使用了代码审核工具Gerrit,那么在进行操作之前需要将Gerrit关掉,等成功恢复后再将Gerrit开户即可

1、使用git push --mirror

先了解一些git的基本参数介绍
git clone --bare

  1. GIT-CLONE(1) Git Manual GIT-CLONE(1)
  2. NAME
  3. git-clone - Clone a repository into a new directory
  4. SYNOPSIS
  5. git clone [--template=<template_directory>]
  6. [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
  7. [-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
  8. [--depth <depth>] [--recursive] [--] <repository> [<directory>]
  9. --bare
  10. Make a bare GIT repository. That is, instead of creating <directory> and placing the administrative files
  11. in <directory>/.git, make the <directory> itself the $GIT_DIR. This obviously implies the -n because there
  12. is nowhere to check out the working tree. Also the branch heads at the remote are copied directly to
  13. corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used,
  14. neither remote-tracking branches nor the related configuration variables are created.

git push --mirror

  1. --mirror
  2. Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited
  3. to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local
  4. refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and
  5. deleted refs will be removed from the remote end. This is the default if the configuration option
  6. remote.<remote>.mirror is set.
1、建立新仓库
  • 1). 从原地址克隆一份裸版本库,比如原本托管于 GitHub,或者是本地的私有仓库
  1. git clone --bare git://192.168.10.XX/git_repo/project_name.git
  • 2). 然后到新的 Git 服务器上创建一个新项目,比如 GitCafe,亦或是本地的私有仓库,如192.168.20.XX
  1. su - git
  2. cd /path/to/path/
  3. mkdir new_project_name.git
  4. git init --bare new_project_name.git
  • 3). 以镜像推送的方式上传代码到 GitCafe 服务器上。
    请确保已经添加了公钥到新的机器上
  1. cd project_name.git
  2. git push --mirror git@192.168.20.XX/path/to/path/new_project_name.git
  • 4). 删除本地代码
  1. cd ..
  2. rm -rf project_name.git
  • 5). 到新服务器上找到 Clone 地址,直接Clone到本地就可以了。
  1. git clone git@192.168.20.XX/path/to/path/new_project_name.git

这种方式可以保留原版本库中的所有内容。

2、切换remote_url

先查看remote的名字

  1. git branch -r

假设你的remote是origin,用git remote set_url 更换地址

  1. git remote set-url origin remote_git_address

remote_git_address更换成你的新的仓库地址。

第二种切换remote_url的方法更直接,直接更改.git/conf配置文件里的ip地址就行。

Yesterday is history.
Tomorrow is a mystery.
But today is a gift.
That is why it's called the present.
The old game: give a wolf a taste, then keep him hungry.

©著作权归作者所有,转载或内容合作请联系作者

3人点赞

前端总结

更多精彩内容,就在简书APP

"小礼物走一走,来简书关注我"

赞赏支持还没有人赞赏,支持一下

家乡_a6ce

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号