如何从共享父目录更新多个git存储库,而不用cd'ing到每个repo的根目录?我有以下所有单独的git存储库(不是子模块):
/plugins/cms
/plugins/admin
/plugins/chart
我想一次更新它们,或者至少简化我当前的工作流程:
cd ~/plugins/admin
git pull origin master
cd ../chart
git pull
etc.
如何从共享父目录更新多个git存储库,而不用cd'ing到每个repo的根目录?我有以下所有单独的git存储库(不是子模块):
/plugins/cms
/plugins/admin
/plugins/chart
我想一次更新它们,或者至少简化我当前的工作流程:
cd ~/plugins/admin
git pull origin master
cd ../chart
git pull
etc.
当前回答
我用的是这个:
find . -name ".git" -type d | sed 's/\/.git//' | xargs -P10 -I{} git -C {} pull
通用:更新当前目录下的所有git存储库。
其他回答
从父目录运行以下命令,在本例中是插件:
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
澄清:
找到。搜索当前目录 -type d查找目录,而不是文件 -depth 1表示最大一个子目录深度 -exec {} \;为每次查找都运行自定义命令 git - git-dir ={} /。git——work-tree=$PWD/{} pull git获取单个目录
要使用find,我建议使用echo after -exec来预览,例如:
find . -type d -depth 1 -exec echo git --git-dir={}/.git --work-tree=$PWD/{} status \;
注意:如果没有-depth 1选项,请尝试-mindepth 1 -maxdepth 1。
这应该是自动发生的,只要cms, admin和chart都是存储库的一部分。
一个可能的问题是这些插件都是git子模块。
运行git帮助子模块查看更多信息。
EDIT
在bash中这样做:
cd plugins
for f in cms admin chart
do
cd $f && git pull origin master && cd ..
done
我的拙见是
显示当前路径(使用python,方便和只是工作,参见如何获得文件的完整路径?) 直接查找.git子文件夹:在非git子文件夹中发出git命令的几率很低 删除一些查找警告
遵循:
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir python -c 'import os; print(os.path.abspath("."))' \; \
-execdir git pull \;
当然,你也可以添加其他带有-execdir选项的git命令,例如显示分支:
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir python -c 'import os; print(os.path.abspath("."))' \; \
-execdir git branch \;
-execdir git pull \;
mr实用程序(又名myrepos)为这个问题提供了一个出色的解决方案。使用您最喜欢的包管理器安装它,或者直接从github中抓取mr脚本,并将其放在$HOME/bin或PATH上的其他地方。然后,cd到这些repo共享的父插件文件夹,并创建一个基本的.mrconfig文件,内容类似于以下(根据需要调整url):
# File: .mrconfig
[cms]
checkout = git clone 'https://<username>@github.com/<username>/cms' 'cms'
[admin]
checkout = git clone 'https://<username>@github.com/<username>/admin' 'admin'
[chart]
checkout = git clone 'https://<username>@github.com/<username>/chart' 'chart'
After that, you can run mr up from the top level plugins folder to pull updates from each repository. (Note that this will also do the initial clone if the target working copy doesn't yet exist.) Other commands you can execute include mr st, mr push, mr log, mr diff, etc—run mr help to see what's possible. There's a mr run command that acts as a pass-through, allowing you to access VCS commands not directly suported by mr itself (e.g., mr run git tag STAGING_081220015). And you can even create your own custom commands that execute arbitrary bits of shell script targeting all repos!
Mr是处理多重回购的一个非常有用的工具。由于plugins文件夹在您的主目录中,您可能对vcsh也感兴趣。与mr一起,它为管理所有配置文件提供了强大的机制。请参阅Thomas Ferris Nicolaisen的这篇博客文章来了解概述。
你可以试试这个
find . -type d -name .git -exec sh -c "cd \"{}\"/../ && pwd && git pull" \;
此外,您还可以通过添加一个&&参数来添加自定义输出。
find . -type d -name .git -exec sh -c "cd \"{}\"/../ && pwd && git pull && git status" \;