星星之火-Git实现代码仓库以及提交记录迁移

本文最后更新于:August 6, 2026 pm

背景:最近因为特殊情况,GitLab重新部署到了另外一台服务器(情况特殊,没有办法正常迁移),所以需要手动迁移一下仓库,但是还需要保留原提交记录,所以记录一下。

目录

环境:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 临时放行内网不安全http (可选操作,遇到SSL问题需要)
git config --global credential.allowUnsafeRemotes true

# 克隆旧仓库
git clone --mirror http://192.168.199.150:8888/lcl/java-system.git

cd java-system.git

# 把origin改成目标新仓库地址
git remote set-url origin http://192.168.199.7:8888/lcl/java-system.git

# 查看旧仓库有哪些分支
git ls-remote --heads http://192.168.199.150:8888/lcl/java-system.git

# 查看当前本地仓库已经拿到的所有分支/tag
git show-ref

# 执行推送:
git push --mirror origin

# 迁移完成,撤销 http 安全豁免(可选操作)
git config --global --unset credential.allowUnsafeRemotes

本文作者: 墨水记忆
本文链接: https://tothefor.com/DragonOne/3a0e6125.html
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!