在`git status`

时间:2019-12-19 22:19:13

标签: git

对于拉取请求,我有:

  • 当地分支机构,例如my-pr-branch
  • @{upstream}分支跟踪PR将被合并到的分支(例如up/master
  • @{push}分支跟踪fork远程分支(例如fork/my-pr-branch

git status很好地显示了@{upstream}的增量,例如:Your branch is up to date with 'up/master'.

但是我真正想要的是同时看到@{upstream}@{push}信息。

我可以手动添加它,但是有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

我的status中具有以下git s别名(我已经运行git status而不是~/.config/git/config

[alias]
  s   = "!git status && git push-status #" # Status including delta from @{push}.

  # Show the status of this branch relative to @{push}.
  push-status = "! push_branch=$(git push-branch 2>/dev/null) || { echo \"No push branch set.\" && exit 0; } \
    ; both=$(git rev-list --left-right --count HEAD...@{push}) \
    ; [[ $both == '0    0' ]] && echo \"Your branch is up to date with push branch $push_branch.\" \
    || echo \"Your branch is ${both%%   *} commit(s) ahead and ${both##*    } commit(s) behind push branch $push_branch.\" #"

这将提供类似于以下内容的输出:

On branch my-pr-branch
Your branch and 'up/master' have diverged,
and have 1 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean
Your branch is 2 commit(s) ahead and 1 commit(s) behind push branch fork/my-pr-branch.

它不如内置的东西好,但是它可以工作。


包含在提示中

要使其显示在提示中,您可能已经从上游获取了增量,您可以使用以下方法简单地进行补充:

# Previous command to check upstream delta:
upstream_delta=$(command git rev-list --left-right --count 'HEAD...@{u}')
# New command to check push delta:
push_upstream_delta=$(command git rev-list --left-right --count 'HEAD...@{push}')

输出看起来像:0 0(两个数字,一个制表符分隔)。第一个数字在前面提交,第二个数字在后面提交。

如果您将⇣⇡用作上游增量,则可能将like用作推送增量。