git 不同仓库 同步

文章详细描述了一段bash脚本,用于在复深蓝代码和上海证券代码库中执行克隆、更新、切换不同分支以及拷贝代码的操作,涉及到gitpull,checkout,merge和push等命令。脚本根据不同参数执行针对不同分支的相应操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参数1:1:克隆分支 2:更新分支 3:切换分支 4:拷贝代码

if_git_pull_or_checkoutBranch=$1

##参数2: 复深蓝代码分支
fulan_branch=$2

##参数2: 项目名称
project_name=$2

##参数3: 上海证券代码分支
securities_branch=$3

#复深蓝代码路径
fulanlinuxPath=‘/d/git-work/fulan’;

上海证券代码路径

securitieslinuxPath=‘/d/git-work/sh-securities’;

#开启扩展通配符
shopt -s extglob

##参数2: 复深蓝代码分支

fulan_branch1=$2

fulan_branch2=$3

fulanArrays=(
‘cloud-base’
‘cloud-knowledge’
‘cloud-xxljob-client’
‘cloud-system’
‘cloud-workflow’
‘cloud-gateway’
‘cloud-parent’
‘cloud-people’
‘cloud-project’
‘front-pc’
‘front-manage’
‘front-h5’
)

   # 克隆分支

if [ $if_git_pull_or_checkoutBranch -eq 1 ]; then
rm -rf $securitieslinuxPath/* f u l a n l i n u x P a t h / ∗ f o r v a l u e i n " fulanlinuxPath/* for value in " fulanlinuxPath/forvaluein"{fulanArrays[@]}"
do
cd $fulanlinuxPath

  if [[ $value =~ 'front' ]]
  then  git clone http://git.biandejun.com/sh-securities-group/front-space/$value.git
  else  git clone http://git.biandejun.com/sh-securities-group/$value.git 
  fi

cp -r ls | grep -v .git | xargs linuxPath

  cd $securitieslinuxPath
  git clone http://10.4.2.100:31101/app_dev/mss/$value.git
done

更新分支

elif [ $if_git_pull_or_checkoutBranch -eq 2 ]; then

#开启模式匹配功能
shopt -s extglob
for value in “${fulanArrays[@]}”
do
cd $fulanlinuxPath
cd $value
git pull
echo -e “\033[0;32m git pull 复深蓝 path = f u l a n l i n u x P a t h / fulanlinuxPath/ fulanlinuxPath/value \033[0m”
cd $securitieslinuxPath
cd $value
git pull
echo -e “\033[0;36m git pull 上海证券 path = s e c u r i t i e s l i n u x P a t h / securitieslinuxPath/ securitieslinuxPath/value \033[0m”
done

# 切换分支  复深蓝代码分支    上海证券代码分支
elif [ $if_git_pull_or_checkoutBranch -eq 3 ]; then
    for value in "${fulanArrays[@]}"
do
  cd $fulanlinuxPath
  cd $value
  git fetch
  git pull
  git checkout $fulan_branch
   git pull
  echo -e "\033[0;32m git checkout 复深蓝 $value branch $fulan_branch \033[0m"
  cd $securitieslinuxPath
  cd $value
  git fetch
  git pull
  git checkout $securities_branch
  git pull
  echo -e "\033[0;36m git checkout 上海证券 $value branch $securities_branch \033[0m"
done

 # 拷贝所有代码
elif [ $if_git_pull_or_checkoutBranch -eq 4 ]; then
    for value in "${fulanArrays[@]}"
do

  cd $fulanlinuxPath
  cd $value
  git pull
  echo -e "\033[0;36m pull 复深蓝 $value \033[0m"


  cd $securitieslinuxPath
  cd $value
  echo -e "\033[0;36m pull 上证 $value \033[0m"


#cloud-parent工程pom.xml手动管理
  if [[ $value =~ 'parent' ]]
  then ls $fulanlinuxPath/$value/ | grep -v 'pom.xml\|.git' | xargs -i cp -rf $fulanlinuxPath/$value/{} $securitieslinuxPath/$value/

#前端工程除了.git全部替换
  elif [[ $value =~ 'front' ]]
  then
 
  rm -rf !(.git)
  ls -A $fulanlinuxPath/$value/ | grep -v '.git' | xargs -i cp -rf $fulanlinuxPath/$value/{} $securitieslinuxPath/$value/

#后端工程删除替换指定文件/目录
  else 
    rm -rf Dockerfile pom.xml src
    ls  $fulanlinuxPath/$value/ | grep -v '.git' | xargs -i cp -rf $fulanlinuxPath/$value/{} $securitieslinuxPath/$value/
   fi
 
  echo -e "\033[0;36m ls $fulanlinuxPath/$value/ | grep -v '.git' | xargs -i cp -r $fulanlinuxPath/$value/{} $securitieslinuxPath/$value/  \033[0m"
  
  cd $securitieslinuxPath
  cd $value
  git pull
    ls -all
  git add .
  git commit -m "fsl合并代码 `date` "
  git push

done

  # 拷贝单个代码
elif [ $if_git_pull_or_checkoutBranch -eq 5 ]; then
    

  cd $fulanlinuxPath
   echo -e "\033[0;36m cd $fulanlinuxPath  \033[0m"
  cd $project_name
  echo -e "\033[0;36m cd $project_name  \033[0m"
  basepath=$(pwd)
  echo -e "\033[0;36m 当前路径:$basepath  \033[0m"
  git pull
  echo -e "\033[0;36m pull 复深蓝 $project_name \033[0m"
 ## rm -rf Dockerfile pom.xml src

  cd $securitieslinuxPath
  echo -e "\033[0;36m cd $securitieslinuxPath  \033[0m"
  cd $project_name
  	  echo -e "\033[0;36m cd $project_name  \033[0m"
	  basepath=$(pwd)
  echo -e "\033[0;36m 当前路径:$basepath  \033[0m"
  git pull
   echo -e "\033[0;36m pull 上海证券 $project_name \033[0m"
   
   
if [[ $project_name =~ 'parent' ]]
  then ls $fulanlinuxPath/$project_name/ | grep -v 'pom.xml\|.git' | xargs -i cp -rf $fulanlinuxPath/$project_name/{} $securitieslinuxPath/$project_name/
   echo -e "\033[0;36m parent服务特殊处理  \033[0m"
  elif [[ $project_name =~ 'front' ]]
  then ls -A $fulanlinuxPath/$project_name/ | grep -v '.git\|public' | xargs -i cp -rf $fulanlinuxPath/$project_name/{} $securitieslinuxPath/$project_name/
  	   echo -e "\033[0;36m 前端服务特殊处理  \033[0m"
  else 
  ls  $fulanlinuxPath/$project_name/ | grep -v '.git' | xargs -i cp -rf $fulanlinuxPath/$project_name/{} $securitieslinuxPath/$project_name/
   echo -e "\033[0;36m 普通服务  \033[0m"
   fi
  echo -e "\033[0;36m ls $fulanlinuxPath/$project_name/ | grep -v '.git' | xargs -i cp -r $fulanlinuxPath/$project_name/{} $securitieslinuxPath/$project_name/  \033[0m"
 
  
  cd $securitieslinuxPath
   echo -e "\033[0;36m cd $securitieslinuxPath  \033[0m"
  cd $project_name
  echo -e "\033[0;36m cd $project_name  \033[0m"
    ls -all
  git add .
  git commit -m 'fsl合并代码'
  git push






   
   #合并分支 把复深蓝分支$fulan_branch1  往分支$fulan_branch2上合并

elif [ KaTeX parse error: Undefined control sequence: \0 at position 56: …hen echo -e "\̲0̲33[0;36m 当前参数:fulan_branch1 $fulan_branch2 \033[0m"

    for value in " ${fulanArrays[@]}"
do
cd $fulanlinuxPath
cd  $value
 basepath=$(pwd)
  echo -e "\033[0;36m 当前路径:$basepath  \033[0m"
git checkout $fulan_branch1
git pull 
echo -e "\033[0;32m git pull fulan path = $fulanlinuxPath/$value    sourebranch: $fulan_branch1  targetbranch: $fulan_branch2  \033[0m"
git checkout $fulan_branch2
 git pull 
git merge $fulan_branch1
git push -u origin $fulan_branch2

echo -e "\033[0;32m 分支 $fulan_branch1 往分支$fulan_branch2 上合并  git merge  fulan path = $fulanlinuxPath/$value  \033[0m"

done

	   
   #合并分支 把上海证券分支$fulan_branch1  往分支$fulan_branch2上合并

elif [ KaTeX parse error: Undefined control sequence: \0 at position 56: …hen echo -e "\̲0̲33[0;36m 当前参数:fulan_branch1 $fulan_branch2 \033[0m"

    for value in " ${fulanArrays[@]}"
do
cd $securitieslinuxPath
cd  $value
 basepath=$(pwd)
  echo -e "\033[0;36m 当前路径:$basepath  \033[0m"
git checkout $fulan_branch1
git pull 
echo -e "\033[0;32m git pull fulan path = $securitieslinuxPath/$value    sourebranch: $fulan_branch1  targetbranch: $fulan_branch2  \033[0m"
git checkout $fulan_branch2
 git pull 
git merge $fulan_branch1
git push -u origin $fulan_branch2

echo -e "\033[0;32m 分支 $fulan_branch1 往分支$fulan_branch2 上合并  git merge  fulan path = $securitieslinuxPath/$value  \033[0m"

done

fi

克隆代码

#./fulan-dh-git.sh 1

更新代码

#./XXX.sh 2

切换分支 dev(上海人寿分支) sit(深蓝云校分支)

#./XXX.sh 3 dev sit

拷贝代码

#./XXX.sh 4

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值