98 lines
2.7 KiB
Bash
98 lines
2.7 KiB
Bash
#!/bin/bash
|
|
# 自动还原git并拉取最新代码
|
|
# 当前目录在C:/Work/Projects/NLDClient/Tool/dll_tools
|
|
# 需要操作目录在C:\Work\Projects\NLDClient\ProjectNLD\Assets\Code\Scripts\GamePlay
|
|
|
|
# 保存初始目录,用于后续返回
|
|
INITIAL_DIR=$(pwd)
|
|
echo "初始目录: $INITIAL_DIR"
|
|
|
|
# 定义目标目录
|
|
TARGET_DIR="../../ProjectNLD/Assets/Code/Scripts/GamePlay"
|
|
|
|
# 先判断目录是否存在, 如果不存在则使用git clone命令克隆, 仓库地址为http://1.14.122.170:3000/PHXH/GamePlay.git
|
|
if [ ! -d "$TARGET_DIR" ]; then
|
|
echo "目录不存在, 尝试克隆仓库..."
|
|
# cd到上级目录
|
|
cd ../../ProjectNLD/Assets/Code/Scripts
|
|
# 检查是否进入成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "错误: 无法进入目录,请检查路径是否正确"
|
|
echo "当前目录: $(pwd)"
|
|
exit 1
|
|
fi
|
|
echo "成功进入目录: $(pwd)"
|
|
git clone http://1.14.122.170:3000/PHXH/GamePlay.git GamePlay
|
|
# 检查克隆是否成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "错误: 克隆仓库失败,请检查网络连接或仓库地址是否正确"
|
|
exit 1
|
|
fi
|
|
cd GamePlay
|
|
# 检查是否进入成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "错误: 无法进入 GamePlay 目录,请检查路径是否正确"
|
|
echo "当前目录: $(pwd)"
|
|
exit 1
|
|
fi
|
|
echo "成功克隆仓库: $TARGET_DIR"
|
|
|
|
# cd 回到原目录
|
|
cd "$INITIAL_DIR"
|
|
echo "成功回到初始目录: $(pwd)"
|
|
fi
|
|
|
|
echo "尝试切换到目录: $TARGET_DIR"
|
|
# cd 到需要操作目录
|
|
cd "$TARGET_DIR"
|
|
# 检查是否进入成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "错误: 无法进入 GamePlay 目录,请检查路径是否正确"
|
|
echo "当前目录: $(pwd)"
|
|
exit 1
|
|
fi
|
|
echo "成功进入目录: $(pwd)"
|
|
|
|
# 检查当前目录是否是git仓库
|
|
if [ ! -d ".git" ]; then
|
|
echo "Current directory is not a git repository"
|
|
exit 1
|
|
fi
|
|
|
|
# 还原所有修改
|
|
git reset --hard HEAD
|
|
# 检查还原是否成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to reset git repository"
|
|
exit 1
|
|
fi
|
|
|
|
# 还原子模块的修改
|
|
echo "Resetting submodules..."
|
|
git submodule foreach --recursive 'git reset --hard HEAD'
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to reset some submodules"
|
|
exit 1
|
|
fi
|
|
|
|
# 拉取最新代码
|
|
git pull
|
|
# 检查拉取是否成功
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to pull latest code from git"
|
|
exit 1
|
|
fi
|
|
# 输出最新的git日志
|
|
echo "Latest git commit log:"
|
|
git log -1 --pretty=format:"%h - %an, %ar : %s"
|
|
|
|
# 更新子模块
|
|
echo "Updating submodules..."
|
|
git submodule update --init --recursive
|
|
if [ $? -ne 0 ]; then
|
|
echo "Failed to update submodules"
|
|
exit 1
|
|
fi
|
|
|
|
# 输出结果
|
|
echo "Git repository reset and pulled successfully" |