git 怎么将一个 patch 文件打到一个目录下的所有 git 仓库

2023-02-13 10:47:44    技术分享   

使用git am命令在一个目录下的所有 Git 仓库中打一个补丁文件。下面是大致的步骤:

1 切换到每个仓库的根目录:

cd /path/to/repo1

2 使用git am命令应用补丁:

git am /path/to/patchfile.patch

3 重复以上步骤,直到每个仓库都应用了补丁。

可以使用脚本来自动地完成这个过程,例如:

#!/bin/bash

PATCH_FILE="/path/to/patchfile.patch"
ROOT_DIR="/path/to/repos"

for dir in $(find $ROOT_DIR -name ".git" -type d | sed 's/\/.git//g'); do
    echo "Applying patch in $dir"
    cd $dir
    git am $PATCH_FILE
done

这个脚本会遍历指定目录(即 /path/to/repos)下的所有 Git 仓库,并且在每个仓库中应用补丁。

QQ
微信