From 8a6c33197aa247b1f45f138f1772838b682ecd22 Mon Sep 17 00:00:00 2001 From: Leon Date: Sun, 8 Aug 2021 20:26:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=82bak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Scripts/sh/gitsync.sh | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Scripts/sh/gitsync.sh diff --git a/Scripts/sh/gitsync.sh b/Scripts/sh/gitsync.sh new file mode 100644 index 0000000..4cf5dfc --- /dev/null +++ b/Scripts/sh/gitsync.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# ========================= +# git 同步脚本 +# +# Author: 余小波 +# Date: 2020-01-09 +# ========================= + +# 本地文件是否发生了改变 +is_change=$(git status -s) + +# 当前分支 +branch=$(git symbolic-ref --short -q HEAD) + +# remark +if [ -n "$1" ]; then + guser=$1 +else + # git.user.name + guser="$(git config user.name) update" +fi + +if [ 0 -lt ${#is_change} ]; then + git add . + git commit -m "$guser" + # pull + result=$(git pull origin $branch) + tmp=$(echo $result | grep "fix conflicts") + if [ "$tmp" != "" ] + then + echo "(ノ=Д=)ノ┻━┻ 合并冲突, 请手动解决后提交" + else + # 推送 + git push origin $branch + fi + +else + echo "本地没有改变, 正在从远程仓库同步代码. 请耐心等待 ╭(●`∀´●)╯╰(●’◡’●)╮"; + result=$(git pull origin $branch) + tmp=$(echo $result | grep "fix conflicts") + if [[ "$tmp" != "" ]] + then + echo "(ノ=Д=)ノ┻━┻ 合并冲突, 请手动解决后提交" + fi +fi \ No newline at end of file