gogs migrate to gitlab

A first idea to chat migration, migration to whether COGS gitlab, or migrate to gitlab COGS, or will migrate to step gitlab gitlab, manual migration are the following (a new empty project on gitlab to FIG. there is such a prompt),

1. Go to the warehouse project, delete the original remote address (the first step in this command I use git remote rm origin)

2. New Specifies the new remote address

3. Upload all local branches to the new remote address

4. Upload all tag to the new remote address

existing_repo cd 
git Remote RM Origin 
git the Add Remote Origin [email protected]: zhouyou / zytest.git 
git Origin --all the Push -u 
git the Push -u Origin the --tags 
2. All items migration, then it must be implemented script implementation steps
1. get all access to the migration project addresses
a. I used this approach to a relatively time-consuming (notepad ++ using skilled, then ten minutes and you get), get items for each person created on gogs server, below, we have the names of all employees in the data directory corresponding gogs

b. then use the command tree -L 2 (see downwardly from the current directory two directories, do not command tree yum install tree -y), FIG. each user can see the items below to paste the copied onto all notepad ++ (may be other text editor), C.

in the text editor will be organized into the following diagram format, access address gogs.haha.local is fixed (for each company's domain name is different, there may be ip), followed by user name and composition of the project, there are rules to follow. Red box at the front is behind the user name password, it will be used (note here, you need to add a generic user to all the items, as shown in my gogsamdin users in all projects) script clone

d then the data in the format of FIG three adjustment, adjusted to recognize the python list data as shown in (notepad ++ can achieve fast, at his level of use of a text editor) shown in FIG.

2.获取到所有项目的访问地址后,我们需要把所有项目clone至本地的一个目录
3.克隆完成后,要对每个项目的所有分支进行checkout,因为上传分支的时候只会将本地所存在的分支上传至远程地址,不存在的不上传。clone完成后本地只有一个master分支,需要想办法获取远程所有分支名称然后checkout一遍
4.checkout完成后,就可以删除旧的源(origin),新增新的源,并把分支和tag上传至新的源
下面附上脚本,一个是python,一个是shell脚本
PS:先执行python脚本,脚本执行完成之后再执行shell脚本,shell脚本的存放目录和gog-to-gitlab3是同一级
gogs_to_gitlab.py
#coding=utf-8
# @Time:2019/7/26 16:52
# @Author:ZHOUYOU
# from git import Repo
# import os
from git import Repo
import git
import os
rep_list  =  ['http://gogsadmin:[email protected]/masibin/fec-device','http://gogsadmin:[email protected]/masibin/fec-install','http://gogsadmin:[email protected]/zhangyan/fec-cms']
path = 'D:\gogs-to-gitlab3'
for i in rep_list:
    #从列表中获取每个项目的项目名称,并创建对应文件夹
    folder = i.split('/',-1)[4]
    print(folder)
    folder_name = './'+folder
    os.mkdir(path+folder_name)
    Repo.clone_from(url=i,to_path=path+folder_name)

    #获取远程分支的分支名称
    repo = git.Repo(path+folder_name)
    remote_branches = []
    for ref in repo.git.branch('-r').split('\n'):
        remote_branches.append(ref)
    print(remote_branches)
    del remote_branches[0]
    print(remote_branches)

    #获取分支名称
    bran_name = []
    for bran in remote_branches:
        print(bran.split('/',-1)[1])
        bran_name.append(bran.split('/',-1)[1])
    print(bran_name)

    #在本地切换一遍分支,因为在上传至新的gitlab库时,只会把已存在的本地分支上传,没有的不会上传,所以必须把所有分支都切换一遍
    for bran in bran_name:
        repo.git.checkout(bran)
#!/bin/sh 
cd gogs-to-gitlab3
for i in `ls`;
do 
echo ======into $i
cd $i
git remote rm origin
git remote add origin http://ip:port/XXXX/$i.git(此处根据自己实际情况填写地址)
git push -u origin --all
git push -u origin --tags
cd ..
done

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zy0209/p/11265158.html