【问题标题】:Run git commands in shell script without change directory to repo在 shell 脚本中运行 git 命令而不将目录更改为 repo
【发布时间】:2015-04-01 01:24:09
【问题描述】:

我正在编写一个 shell 脚本 (zsh),它将为一组目录运行 git 命令。其中一些是带有.rvmrc 文件的项目,可能需要一段时间才能运行。当我 cd 进入目录运行命令时,它会激活 .rvmrc 这确实会减慢脚本的速度。

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

我想在我的脚本目录中运行不带cding 的命令,或者暂时停用.rvmrc 文件,以便cding 进入目录不会运行rvmrc。

有什么想法吗?

【问题讨论】:

  • 提议的副本('git pull while not in a git directory')似乎与已接受的(仅)答案涵盖相同的基础,但尚不完全清楚如何/为什么逃避Ruby 版本管理器的问题(似乎与 .rmvrc 文件相关)。

标签: git shell rvm


【解决方案1】:

你可以指定git工作目录和.git位置:

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

还有环境参数可用,请查看manuals

【讨论】:

    猜你喜欢
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多