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

4次阅读

共计 391 个字符,预计需要花费 1 分钟才能阅读完成。

应用 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 仓库,并且在每个仓库中利用补丁。

正文完
 0