sh 将一个git repos复制到另一个

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将一个git repos复制到另一个相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# LOAD Functions and common vars
source ./func.sh

# ssh-agent /bin/bash -c " << EOF
# ssh-add ~/.ssh/id_rsa_git
if ! ssh -T -o PasswordAuthentication=no git@.... 1> /dev/null;
then

  echo " *** Dont forget to run the ssh-agent and ssh-add command before running this script "
  echo " commands: "
  echo "
        ssh-agent /bin/bash
        ssh-add ~/.ssh/id_rsa_git
";
exit 255;
fi
# read source and target repo from config.txt
# clone source remopo to some place (temp folder)

# see if there is a folder with target repo
#   if not - make git clone
#   if there is a folder with target repo - make git pull in this repo

# remove .git dir from source repo folder
# if in source repo folder common folder exists remove common/.git folder and .gitmodules file
# copy files (except .git folder) from source repo folder to target repo folder
# commit the changes in target repo
# push changes to target repo

CONFIG_FILE="$PWD/config.txt"
WORKING_DIR="$PWD/tmp$$";

cd tmp
mkdir $$
cd $$
set -x
for reg in `cat $CONFIG_FILE`;
do
echo $reg
set +x

set -x

      SRC_REPO=`echo $reg | awk -F\; '{print $1}'`;
      DEST_REPO=`echo $reg | awk -F\; '{print $2}'`;
      TMP_FOLDER=`echo $SRC_REPO | awk -F\/ '{print $NF}'`;
      TMP_DEST_FOLDER=`echo $DEST_REPO | awk -F\/ '{print $NF}' | sed 's/\.git//g'`;
      echo "$SRC_REPO|$DEST_REPO|$TMP_FOLDER|$TMP_DEST_FOLDER";

      echo "***********************************************"
      echo "     Source Repo: $SRC_REPO\t  "
      echo "Destination Repo: $DEST_REPO\n\n"

      cd $WORKING_DIR;

      git clone --recursive $SRC_REPO;
      test_return "git clone $SRC_REPO";
      cd $TMP_FOLDER;
      test_return "cd $TMP_FOLDER";
      rm -fR .git
      test_return "rm .git in $TMP_FOLDER";

      if [ -d common/.git ];
      then
         rm -fR common/.git;
         rm .gitmodules
      fi

      cd ..

      git clone $DEST_REPO;
      test_return "git clone $DEST_REPO";

      cd $TMP_DEST_FOLDER
      test_return "changing directory into $DEST_REPO";

      cp -pR ../$TMP_FOLDER/* .;
      test_return "error in cp from $SRC_REPO to $DEST_REPO";

      git add .;

      git commit -m "Automatic update $$";
      echo "|$?|";
      echo "############################################"
      echo " GIT STATUS "
      git status;
      echo "############################################"

      git push origin master;
      echo "|$?|";

      echo "***********************************************\n\n"
      cd ..

done

以上是关于sh 将一个git repos复制到另一个的主要内容,如果未能解决你的问题,请参考以下文章

markdown 将git stashes从一个repo移动到另一个repo

如何将文件夹从 git repo 链接到另一个 repo?

将 git repo 合并到另一个 repo 的分支中

Git将包含所有子模块的repo镜像到另一个repo

如何删除git嵌套repo但保留其中一个分支的文件?

如何将一些文件从一个 git repo 移动到另一个(不是克隆),保留历史记录