git - 在 `git status` 中显示 @{push} 和 @{upstream} 的状态
问题描述
对于拉取请求,我有:
- 本地分支机构,例如
my-pr-branch
@{upstream}
跟踪 PR 将合并到的分支的分支(例如up/master
)- 跟踪 fork 远程分支的
@{push}
分支(例如fork/my-pr-branch
)
git status
很好地显示了@{upstream}
增量,例如:Your branch is up to date with 'up/master'.
但我真正想要的是同时看到@{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.
它不如内置的东西好,但它可以工作。
包括在提示中
为了让它显示在您的提示中,您可能已经从上游获取了增量,您可以简单地通过以下方式对其进行扩充:
# 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
两个数字用制表符分隔)。第一个数字是前面提交,第二个是后面提交。
如果您使用 ⇣⇡ 表示上游增量,您可能会喜欢 ⇠⇢ 表示推送增量。
推荐阅读
- reactjs - 反应 useEffect 功能有问题
- python - Numpy:读取任意数量的 .txt 文件并将数据保存在一个 numpy 数组中
- r - 将多列收集为一个键和两个值
- amazon-web-services - 带有 ASG 名称更改的 AWS 云观察指标
- php - 什么是关于数据库的原子事务,我如何在 Laravel 中实现它?
- r - 一次将 dplyr 函数应用于所有变量
- jenkins - 在 Jenkins 模板引擎中使用实用程序脚本
- zeromq - ZMQ PUB/SUB 套接字低负载下的高延迟
- javascript - 在按钮上设置 Cookie
- javascript - 出现错误:未捕获的 ReferenceError:gsap 未在基本 HTML/CSS/JS 页面上定义