我有一个文件夹 - 'Repos' - 其中包含我感兴趣的存储库。这些是从 bitbucket 克隆的,但我想 github 也可能是一个来源。
Repos
- music-app
- elephant-site
- node-demo
是否有一个 git 命令,我可以使用它来遍历 Repos 中的每个文件夹,并查看服务器上是否有新的提交,并下载新的内容?如果本地有新的提交,则上传这些。
试试这个:
cd repos
find . -maxdepth 1 -type d -exec sh -c '(cd {} && git pull)' ';'
对于 Windows,我在 .cmd 文件中使用以下内容。它可以轻松扩展以做更多事情或其他事情:
for /d %%i in (*) do (
pushd "%%i"
git pull
popd
)
对于 Windows,这应该通过命令提示符为您完成:
cd c:\repos
for /d %a in (*.*) do cd c:\repos\%a && git pull
返回 GitHub 客户端后,您应该会看到更新。
使用 powershell 你可以这样做:
Get-ChildItem -Recurse -Depth 2 -Force |
Where-Object { $_.Mode -match "h" -and $_.FullName -like "*\.git" } |
ForEach-Object {
cd $_.FullName
cd ../
git pull
cd ../
}
这将进入每个目录并查找
.git
文件夹,然后在每个文件夹中运行 git pull
。
gitfox 是一个在所有子存储库上执行命令的工具
npm 安装 gitfox -g
拉动
要维护多个存储库,您可以使用 git 子模块。
使用
git submodule add
将存储库添加为子模块,并使用 git submodule foreach git pull
更新存储库。
这个方法就像你有一个超级项目,里面有几个git项目。
我有一个脚本,它可以执行以下操作:
for d in *
cd $d
git pull
cd ..
(是的,它有一些额外的功能,因为我有一些
hg
存储库,以及我从 SVN 上游在 git 中管理的其他存储库。)
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin \;
归功于Leo
我在给定的答案中没有看到任何解决此问题的方法,但是修改所选答案以避免拉动“./”存储库的一个好方法是在 find 上设置 mindepth 值。以下表达式解决了 OP 问题,同时还消除了所选答案遇到的错误:
cd repos
find . -mindepth 1 -maxdepth 1 -type d -exec sh -c '(cd {} && git pull)' ';'
这适用于大多数 *nix 系统,并且应该适用于 mac。
myrepos
。
您有很多版本控制存储库。有时您想一次性更新它们。或者推出所有本地更改。您可以在某些存储库中使用特殊的命令行来实现特定的工作流程。 Myrepos 提供了 mr 命令,这是一个管理所有版本控制存储库的工具。
cd repos
find . -type d -depth 1 -exec mr register {} \
mr update