简体   繁体   English

在shell脚本中运行git命令,而无需将目录更改为repo

[英]Run git commands in shell script without change directory to repo

I'm writing a shell script (zsh) that will run git commands for a set of directories. 我正在写一个shell脚本(zsh),它将对一组目录运行git命令。 Some of these are projects with .rvmrc files which can take a while to run. 其中一些是带有.rvmrc文件的项目,可能需要一段时间才能运行。 When I cd into the directory to run a command, it activates the .rvmrc which really slows down the script quite a bit. 当我cd到该目录中运行命令,它会激活.rvmrc这确实减慢脚本不少。

Example command: $(cd $dir && exec git branch) 示例命令: $(cd $dir && exec git branch)

I would like to either run the commands without cd ing into the directory in my script, or temporarily deactivate the .rvmrc file so cd ing into the directory does not run the rvmrc. 我想运行命令而不将其cd进入脚本的目录,或者暂时停用.rvmrc文件,以便使cd进入目录不会运行rvmrc。

Any thoughts? 有什么想法吗?

you can specify the git working directory and .git location: 您可以指定git工作目录和.git位置:

git --work-tree=$dir --git-dir=$dir/.git branch
git -C $dir branch

There are also environmental parameter available, please check the manuals 也有可用的环境参数,请检查手册

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM