使用Git与SVN双向同步
使用git svn指令在Coding.net实现Git和SVN双向同步
请严格按照下图步骤操作,实战中如果漏了步骤或顺序乱了,在最终提交时会出现怎么都消除不了的错误:Unable to determine upstream SVN information from HEAD history. Perhaps the repository is empty. at C:/Program Files/Git/mingw64/libexec/git-core\git-svn line 916.
指令汇总如下:
$ mkdir localSvn
$ cd localSvn/
$ git svn clone https://svn.coding.net/sdjq/coding-devops-guide/yjptnet -s
$ ls yjptnet
$ cd yjptnet/
$ ls
$ git status
创建文件helloworld.txt
$ git status
$ git add .
$ git status
$ git commit -m ' init commit'
$ git svn dcommit
以下是在Coding.net上使用成功的Jenkins脚本:
pipeline {
agent any
stages {
stage('检出') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: GIT_BUILD_REF]],
userRemoteConfigs: [[
url: GIT_REPO_URL,
credentialsId: CREDENTIALS_ID
]]])
sh '''pwd
ls'''
}
}
stage('自定义构建过程') {
steps {
echo '正在推送文件...'
sh '''sudo apt-get --yes --allow-downgrades --allow-remove-essential --allow-change-held-packages install git-svn
pwd
ls
cd ..
mkdir localSVN
cd localSVN/
echo cqh123456. | git svn --username sd_cqh clone -s http://47.104.144.219:8080/svn/硬件驱动产品
ls 硬件驱动产品
cd 硬件驱动产品/
git status
rsync -av --progress /root/workspace/ /root/localSVN/硬件驱动产品/ --exclude .git
pwd
ls
git status
git add .
git status
git commit -m \' init commit\'
git svn dcommit'''
}
}
}
}
注:
- 上述有一步复制文件指令:
rsync -av --progress /root/workspace/ /root/localSVN/硬件驱动产品/ --exclude .git
.如果此步骤使用cp -r /root/workspace/. /root/localSVN/硬件驱动产品
,会把.git文件夹一齐复制过去,会造成git HEAD 游离的异常状态,错误提示如下:这样就无法在master主干上添加新文件并成功提交,即使是git checkout master切换回主干也很麻烦还要合并融合等操作消除游离状态.[2022-03-25 22:29:43] + git status [2022-03-25 22:29:44] HEAD detached at 5048d3e [2022-03-25 22:29:44] nothing to commit, working tree clean
指令中的@在url中需要写成%40的UTF8形式,如: git clone https://12293669%40qq.com:D123456@e.coding.net/sdjq/paas_hardware/paasplugins.git base
参考资料
git-svn dcommit error: unable to determine upstream SVN information,仅供参考,实战中无效
,git-svn: Unable to determine upstream SVN information from working tree history- :git-svn 使用,实战中一直报:Unable to determine upstream SVN information from HEAD history. Perhaps the repository is empty. at C:/Program Files/Git/mingw64/libexec/git-core\git-svn line 916.