最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Gitlab中尝试用clone加mirror参数实现git仓库整体迁移且带历史提交日志

Git crifan 419浏览 0评论
折腾:
【未解决】Gitlab的旧git仓库迁移到新仓库且保留commit历史记录
期间,再去试试后来知道的
git clone 加上 –mirror参数的流程,看看能否实现整体迁移git项目。
git repo whole transfer
How to move a git repository with history | Atlassian Git Tutorial
虽然手动操作麻烦点,但是貌似是可行的。
Transferring a repository – GitHub Docs
macos – Move Git repo A into Git repo B (Not empty) with complete history – Stack Overflow
Git Repository Transfer Keeping All History | by Nassos Michas | ITNEXT
git clone --mirror old-repo-url new-repo

cd new-repo
git remote remove origin

git remote add origin new-repo-url

git push --all
git push --tags
再去:
cd ..
rm -rf new-repo
git clone new-repo-url new-repo
好像不错。去操作试试。
git clone --mirror http://xxx:12310/data/data_xxx/appcrawler.git
log
xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer  git clone --mirror http://xxx:12310/data/data_xxx/appcrawler.git
Cloning into bare repository 'appcrawler.git'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (310/310), done.
remote: Compressing objects: 100% (149/149), done.
remote: Total 2384 (delta 208), reused 236 (delta 157)
Receiving objects: 100% (2384/2384), 1.88 MiB | 1.47 MiB/s, done.
Resolving deltas: 100% (1469/1469), done.
但是此处出现的目录是appcrawler.git
  ll
total 0
drwxr-xr-x  10 xxx  CORP\Domain Users   320B  7 15 15:23 appcrawler.git
看起来不正常?
去看看文件:
 cd appcrawler.git
 xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/appcrawler.git   master  ll
total 32
-rw-r--r--   1 xxx  CORP\Domain Users    23B  7 15 15:23 HEAD
-rw-r--r--   1 xxx  CORP\Domain Users   238B  7 15 15:23 config
-rw-r--r--   1 xxx  CORP\Domain Users    73B  7 15 15:23 description
drwxr-xr-x  13 xxx  CORP\Domain Users   416B  7 15 15:23 hooks
drwxr-xr-x   3 xxx  CORP\Domain Users    96B  7 15 15:23 info
drwxr-xr-x   4 xxx  CORP\Domain Users   128B  7 15 15:23 objects
-rw-r--r--   1 xxx  CORP\Domain Users   105B  7 15 15:23 packed-refs
drwxr-xr-x   4 xxx  CORP\Domain Users   128B  7 15 15:23 refs
果然不正常-》原先项目代码都彻底没了!!!
看来是之前的:
【未解决】Gitlab中尝试通过Transfer project去整体迁移一个git仓库
Transfer失败,导致项目数据丢失了???
那去clone新的git试试?
(虽然Gitlab网页中显示是空的)
git clone http://xxx:12310/data_xxx/appcrawler.git
log
 git clone http://xxx:12310/data_xxx/appcrawler.git
Cloning into 'appcrawler'...
remote: The project you were looking for could not be found.
fatal: repository 'http://xxx:12310/data_xxx/appcrawler.git/' not found
找不到:则是正常现象。毕竟的确没Transfer过去。
重新clone,不加mirror试试?
git clone http://xxx:12310/data/data_xxx/appcrawler.git
Cloning into 'appcrawler'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (310/310), done.
remote: Compressing objects: 100% (149/149), done.
remote: Total 2384 (delta 208), reused 236 (delta 157)
Receiving objects: 100% (2384/2384), 1.88 MiB | 1.66 MiB/s, done.
Resolving deltas: 100% (1469/1469), done.
结果:
 xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/new_appcralwer  ll
total 0
drwxr-xr-x  22 xxx  CORP\Domain Users   704B  7 15 15:28 appcrawler
 xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/new_appcralwer  cd appcrawler
 xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/new_appcralwer/appcrawler   master  ll
total 120
-rw-r--r--   1 xxx  CORP\Domain Users    27K  7 15 15:28 README.md
-rw-r--r--   1 xxx  CORP\Domain Users   2.4K  7 15 15:28 analyzeStart.py
-rw-r--r--   1 xxx  CORP\Domain Users   7.2K  7 15 15:28 crawlerStart.py
drwxr-xr-x   7 xxx  CORP\Domain Users   224B  7 15 15:28 gameAutomation
drwxr-xr-x   5 xxx  CORP\Domain Users   160B  7 15 15:28 iOSAutomation
drwxr-xr-x  24 xxx  CORP\Domain Users   768B  7 15 15:28 middleware
drwxr-xr-x   7 xxx  CORP\Domain Users   224B  7 15 15:28 platformIntegration
drwxr-xr-x  13 xxx  CORP\Domain Users   416B  7 15 15:28 process
-rw-r--r--   1 xxx  CORP\Domain Users   2.6K  7 15 15:28 queryService.py
-rw-r--r--   1 xxx  CORP\Domain Users   2.6K  7 15 15:28 queryService1.py
-rw-r--r--   1 xxx  CORP\Domain Users   4.5K  7 15 15:28 requirements.txt
drwxr-xr-x   6 xxx  CORP\Domain Users   192B  7 15 15:28 service
drwxr-xr-x   7 xxx  CORP\Domain Users   224B  7 15 15:28 src
-rw-r--r--   1 xxx  CORP\Domain Users    72B  7 15 15:28 stop_mongod.js
drwxr-xr-x   5 xxx  CORP\Domain Users   160B  7 15 15:28 tmp
drwxr-xr-x  17 xxx  CORP\Domain Users   544B  7 15 15:28 tool
drwxr-xr-x   5 xxx  CORP\Domain Users   160B  7 15 15:28 utils
就是有文件的。
-》说明mirror的clone是没问题的
-》说明之前Transfer失败,并不影响原有此处git仓库数据
-》说明上面看到目录是appcrawler.git 以及其下没有源码 是正常的
那就继续:
发现前面命令中少了个new-repo
重新试试
git clone --mirror http://xxx:12310/data/data_xxx/appcrawler.git appcrawler
log
 git clone --mirror http://xxx:12310/data/data_xxx/appcrawler.git appcrawler
Cloning into bare repository 'appcrawler'...
remote: Enumerating objects: 310, done.
remote: Counting objects: 100% (310/310), done.
remote: Compressing objects: 100% (149/149), done.
remote: Total 2384 (delta 208), reused 236 (delta 157)
Receiving objects: 100% (2384/2384), 1.88 MiB | 1.50 MiB/s, done.
Resolving deltas: 100% (1469/1469), done.
然后去:
 cd appcrawler
 xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/appcrawler   master  git status
fatal: this operation must be run in a work tree
好像git都支持?
继续试试:
 git remote remove origin
Note: A branch outside the refs/remotes/ hierarchy was not removed;
to delete it, use:
  git branch -d master
的确有警告,暂时忽略
git remote add origin http://xxx:12310/data_xxx/appcrawler.git
不过在此之前,先去新建一个空项目:
http://xxx:12310/data_xxx/appcrawler.git
http://gitlab.xxx.corp.com/data_xxx/appcrawler
git地址:
http://xxx:12310/data_xxx/appcrawler.git
继续:
 git remote add origin http://xxx:12310/data_xxx/appcrawler.git
继续:
git push --all
结果:
【已解决】迁移Gitlab的git项目期间报错:A default branch e.g. master does not yet exist
然后就可以了:
 ✘ xxx@xxx  ~/dev/xxx/crawler/appAutoCrawler/gitlab/transfer/appcrawler   master  git push --all
Enumerating objects: 2384, done.
Counting objects: 100% (2384/2384), done.
Delta compression using up to 8 threads
Compressing objects: 100% (848/848), done.
Writing objects: 100% (2384/2384), 1.88 MiB | 49.28 MiB/s, done.
Total 2384 (delta 1469), reused 2384 (delta 1469)
remote: Resolving deltas: 100% (1469/1469), done.
To http://xxx:12310/data_xxx/appcrawler.git
 * [new branch]      master -> master
再去:
git push --tags
log
  git push --tags
Everything up-to-date
去新git仓库看看内容是否都有了:
真的全部都有了。
至此,算是整体迁移单个git仓库,且保留历史记录,就OK了。
然后去重新下载新仓库看看
  git clone http://xxx:12310/data_xxx/appcrawler.git
Cloning into 'appcrawler'...
remote: Enumerating objects: 2384, done.
remote: Counting objects: 100% (2384/2384), done.
remote: Compressing objects: 100% (848/848), done.
remote: Total 2384 (delta 1469), reused 2384 (delta 1469)
Receiving objects: 100% (2384/2384), 1.88 MiB | 341.00 KiB/s, done.
Resolving deltas: 100% (1469/1469), done.
下载后,去看看大小:
有7M多。
去VSCode中看看:
代码也是对的。
【总结】
此处,想要把git仓库,整体迁移,且保留全部历史commit提交记录,步骤是:
git clone --mirror old-repo-url new-repo

cd new-repo
git remote remove origin

git remote add origin new-repo-url

git push --all
git push --tags
后记[可选]:
cd ..
rm -rf new-repo
git clone new-repo-url new-repo
其中把new-repo-url和 new-repo 换成你自己的仓库
此处自己的操作:
(1)以镜像方式下载复制代码
git clone --mirror http://xxx:12310/data/data_xxx/appcrawler.git appcrawler
说明:
此处的:
git clone --mirror <url to ORI repo> temp-dir
等价于:
git clone <url to ORI repo> temp-dir

git branch -a

git checkout branch-name

git fetch --tags

git tag
git branch -a
(2)删除本地的远端的分支
cd appcrawler
git remote remove origin
其中会有提示,意思好像是:有其他额外的分支?
总之可以忽略不管。
注:
  • git remote remove origin
    • 另一种写法:
      • git remote rm origin
(3)添加远端地址为新仓库
git remote add origin http://xxx:12310/data_xxx/appcrawler.git
(4)提交上传所有代码和标签
上传所有代码:
git push --all
或:
git push origin --all
和  所有标签:
git push --tags
即可。

转载请注明:在路上 » 【已解决】Gitlab中尝试用clone加mirror参数实现git仓库整体迁移且带历史提交日志

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.175 seconds, using 21.62MB memory