[英]How to show log between current branch and its remote counterpart
Sometimes after fetching from remote repository I see my branch is behind:有时从远程存储库获取后,我看到我的分支落后了:
> git status
On branch develop
Your branch is behind 'origin/develop' by 7 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Before updating my local branch I would like to see the log of what I'm about to get.在更新我的本地分支之前,我想查看我将要获得的日志。 I can do it using
我可以使用
> git log develop..origin/develop
Since I'm already on the develop
branch, is there a way to do the above with less typing?由于我已经在
develop
分支上,有没有办法用更少的输入来完成上述操作? That is, without providing local and remote branch names?也就是说,不提供本地和远程分支名称?
This would be especially useful since I often switch to feature branches and would like to see such logs for those, too.这将特别有用,因为我经常切换到功能分支并且也希望查看这些日志。
Yes, a short and branch-agnostic way is to use the @{upstream}
construct :是的,一个简短且与分支无关的方法是使用
@{upstream}
构造:
git log ..@{u}
(Note : since the first part of the range is omitted here, HEAD
is implied, but the full verbose syntax would be HEAD..HEAD@{upstream}
.) (注意:由于此处省略了范围的第一部分,因此暗示了
HEAD
,但完整的详细语法将是HEAD..HEAD@{upstream}
。)
And of course it's very handy to have it as alias.behind
(for example) since it'll use whatever branch you're on.当然,将它作为
alias.behind
(例如)非常方便,因为它会使用你所在的任何分支。
Edit after comments : I added the useful counterpart alias.ahead
to check commits about to be pushed (there's a catch : while @{upstream}
refers to the remote branch where your config will pull from , the branch set in config to push to is @{push}
( doc )).评论后编辑:我添加了有用的对应
alias.ahead
来检查即将被推送的提交(有一个问题:虽然@{upstream}
指的是您的配置将从中提取的远程分支,但在配置中设置的分支是推送到@{push}
( 文档))。 In some specific 3-way settings, these may differ, but in most simple workflows both point to the same branch of the same remote.在某些特定的 3 向设置中,它们可能会有所不同,但在大多数简单的工作流程中,它们都指向同一个遥控器的同一个分支。 But it's just in case.
但以防万一。
git config --global alias.behind 'log [any format option you prefer] ..@{u}'
git config --global alias.ahead 'log [any format option you prefer] @{push}..'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.