git资源库完整迁移
要求如下
代码仓库全量迁移、提交历史保留、分支保留、标签保留
第一步 本地clone最新远端项目代码
注:确保提交前本地代码已提交到远程资源库
git clone --bare <旧仓库git地址>
--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 --no-checkout 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仓库。不是工作区,所以不能checkout。远端资源库也是直接复制到本地资源库,而不是映射。既不会创建远程跟踪记录,也不会创建创建配置。
第二步 本地项目推送到远端
注:使用非HTTP方式,请确保已经添加了公钥到新的机器上
git push --mirror <迁移目标仓库git地址>
--mirror
Instead of naming each ref to push, specifies that all refs underrefs/
(which includes but is not limited torefs/heads/
,refs/remotes/
, andrefs/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 optionremote.<remote>.mirror
is set.
大概意思
不是将每个ref都命名为 push,而是指定将 refs/下的所有 ref(包括但不限于 refs/heads/、refs/remotes/ 和 refs/tags/)镜像到远程仓库。新创建的本地 refs 将被推送到远程端,本地更新的 refs 将在远程端强制更新,删除的 refs 将从远程端移除。
第三步 检查
git clone <迁移后仓库git地址>
git log
...
或者
通过git远端管理页面查看分支、提交历史、标签等
第四步 删除本地代码
rm -rf <本地代码路径>
标签:git,资源库,--,refs,Git,本地,remote,迁移 From: https://www.cnblogs.com/ywzq/p/16769605.html