以`git status`显示@ {push}和@ {upstream}的状态

问题描述 投票:0回答:1

对于拉取请求,我有:

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

@{push}很好地显示了fork/my-pr-branch增量,例如:git status

但是我真正想要的是同时看到@{upstream}Your branch is up to date with 'up/master'.信息。

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

git
1个回答
0
投票
我在@{upstream}中具有以下@{push}别名(我已经运行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.
(两个数字,用制表符分隔)。第一个数字在前面提交,第二个数字在后面提交。

如果在上游增量中使用,,则可能在推送增量中使用⇠⇢。

© www.soinside.com 2019 - 2024. All rights reserved.