0

通常git status显示:

  1. 当前分支名称(或分离的 HEAD 状态)
  2. 上游分支(如果有)是否领先、落后或发散
  3. 已更改暂存以进行提交
  4. 未为提交暂存的更改
  5. 未跟踪的文件

如何只查看 1 和 2 而没有文件信息?git status的选项通常会影响文件的显示,并且尝试使其更短通常会完全删除分支状态摘要。

我希望看到这样的事情:

On branch mybranch
Your branch is behind 'origin/mybranch' by 7 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

没有别的。

是否有一些 git 命令专门显示此信息?

4

1 回答 1

1
# Branch name or commit hash if detached HEAD
git symbolic-ref --quiet --short HEAD 2> /dev/null || \
    git rev-parse --short HEAD 2> /dev/null

# Check if an upstream branch is configured for the current branch
up=`git rev-parse --abbrev-ref @{u} 2>/dev/null`
if [ -n "$up" -a "$up" != "@{u}" ]; then
    # Count the number of commits ahead/behind the upstream
    git rev-list --count --left-right @{u}...HEAD
fi

您可以从中创建一个 git 别名或 shell 脚本。

于 2021-04-13T18:07:23.050 回答