From 075bfebd0b9818395540b053ded7d0af060f58e1 Mon Sep 17 00:00:00 2001 From: HeXiangLong <3234374354@qq.com> Date: Thu, 20 Mar 2025 12:49:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20git=5Fsync.sh=20=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E6=97=A5=E5=BF=97=E4=BF=A1=E6=81=AF=EF=BC=8C=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E6=8F=90=E7=A4=BA=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- git_sync.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/git_sync.sh b/git_sync.sh index 4b94edac..f86b0eea 100755 --- a/git_sync.sh +++ b/git_sync.sh @@ -7,12 +7,12 @@ log() { # 检查是否在 Git 仓库中 if [ ! -d .git ]; then - log "当前目录不是一个 Git 仓库,请在 Git 仓库中运行此脚本。" + log "当前目录不是一个 Git 仓库." exit 1 fi # 处理空目录,添加 .gitkeep 文件 -log "检查并处理空目录..." +log "检查空目录..." for dir in $(find . -type d); do if [ -z "$(ls -A "$dir")" ]; then touch "$dir/.gitkeep" @@ -21,14 +21,14 @@ for dir in $(find . -type d); do done # 1. 暂存所有更改 -log "开始暂存所有更改..." +log "暂存所有更改..." git add . 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" done log "暂存完成." # 2. 提交更改 -log "开始提交更改..." +log "提交更改..." commit_message="[$(date '+%Y-%m-%d %H:%M:%S')]-自动同步" git commit -m "$commit_message" 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" @@ -36,27 +36,27 @@ done log "提交完成." # 3. 推送更改到远程仓库 -log "开始推送更改到远程仓库..." +log "推送更改到远程仓库..." git push origin main 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" done log "推送完成." # 4. 从远程仓库拉取最新代码 -log "开始从远程仓库拉取最新代码..." +log "从远程仓库拉取最代码..." git fetch origin 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" done # 5. 解决冲突(如果需要) -log "尝试合并远程分支到本地分支..." +log "尝试合并远程分支到本地..." git merge origin/main --allow-unrelated-histories -X theirs 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" done # 检查是否存在冲突 if [ $? -ne 0 ]; then - log "检测到合并冲突,正在尝试自动解决冲突(以远程仓库为准)..." + log "合并冲突,尝试自动解决(以远程仓库为准)..." git checkout --theirs . 2>&1 | while IFS= read -r line; do echo "$(date '+%Y-%m-%d %H:%M:%S') [GIT] $line" done @@ -69,4 +69,4 @@ if [ $? -ne 0 ]; then log "冲突解决完成." fi -log "同步完成,所有操作结束。" \ No newline at end of file +log "同步完成!" \ No newline at end of file