【问题标题】:Git top level dir NameGit 顶级目录名称
【发布时间】:2015-12-07 05:25:38
【问题描述】:

我正在尝试检索顶级目录名称,但 $GIT var 返回为空?这是用于终端中的 git 集成。

function root_func() {
    GIT="git rev-parse --is-inside-work-tree"
    if [[ $GIT =~ "True" ]]; then
    git rev-parse --show-toplevel | awk 'BEGIN{FS="/"}{print $(NF-0)}'
    fi  }

【问题讨论】:

  • 我知道真/真。出于某种原因,我与任何一个都没有区别。从术语来看,它只是返回空?

标签: git macos terminal


【解决方案1】:
GIT="git rev-parse --is-inside-work-tree"

这只是将GIT 设置为一个字符串。我想你真的想要

GIT=$(git rev-parse --is-inside-work-tree)

你也可以很容易地做到这一点:

git rev-parse --is-inside-work-tree >/dev/null 2>&1 && basename $(git rev-parse --show-toplevel)

【讨论】:

    猜你喜欢
    • 2017-05-15
    • 2012-05-25
    • 2019-05-23
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多