应用git am命令在一个目录下的所有 Git 仓库中打一个补丁文件。上面是大抵的步骤:
1 切换到每个仓库的根目录:
cd /path/to/repo1
2 应用git am命令利用补丁:
git am /path/to/patchfile.patch
3 反复以上步骤,直到每个仓库都利用了补丁。
能够应用脚本来主动地实现这个过程,例如:
#!/bin/bashPATCH_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_FILEdone
这个脚本会遍历指定目录(即 /path/to/repos)下的所有 Git 仓库,并且在每个仓库中利用补丁。