先了解一些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=]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o ] [-b ] [-u ] [--reference ]
[--depth ] [--recursive] [--] []
--bare
Make a bare GIT repository. That is, instead of creating and placing the administrative files
in /.git, make the 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..mirror is set.
1、建立新仓库
git clone --bare git://192.168.10.XX/git_repo/project_name.git
su - git
cd /path/to/path/
mkdir new_project_name.git
git init --bare new_project_name.git
cd project_name.git
git push --mirror [email protected]/path/to/path/new_project_name.git
cd ..
rm -rf project_name.git
git clone [email protected]/path/to/path/new_project_name.git
这种方式可以保留原版本库中的所有内容。
先查看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地址就行。
完整迁移,就是指,不仅将所有代码移植到新的仓库,而且要保留所有的commit记录
1. 随便找个文件夹,从原地址克隆一份裸版本库
git clone --bare 旧的git地址
会在当前目录下产生一个 xxx.git 的文件夹
这个步骤,就是克隆git每一次的提交信息
和本地的代码没有关系,只要线上的代码是最新的,这个git版本就是完整的
2. 推送裸版本库到新的地址
cd xxx.git
git push --mirror 新的git地址
3. 删掉xxx.git文件夹
删不删无所谓,只是说明它没有用了而已。
4. 代码迁移就成功了,接下来就可以使用新的地址了
git clone 新的git地址
作者:陌上冰火
链接:https://www.jianshu.com/p/59516a17fcf3
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
转载于:https://www.cnblogs.com/ZhangRuoXu/p/6706530.html