简体   繁体   English

查找也存在于/被推送到上游的最后一个本地git commit

[英]Find the last local git commit that is also present in/was pushed to upstream

Is there a way to get the last local Git commit that I also pushed on upstream? 有没有办法获取我也在上游推送的最后一个本地Git提交?

To explain a little more: I would like the last local commit that was also pushed on upstream, not to be confused by the last upstream commit which is not always also local(because you can bring upstream commits using git fetch and the fetched commits are not local anymore). 进一步解释:我希望最后一个本地提交也被推送到上游,不要被最后一个上游提交所混淆,后者也不总是本地的(因为您可以使用git fetch带来上游提交,并且获取的提交是不再是本地的)。

I understand that one could make an algorithm that looks over the upstream commits and over the local commits, does some comparisons and determine which was the last local commit ie that appears when git log ing and is also present in upstream but a git command that gives this information would be very handy. 我知道可以制作一种算法,该算法可以查看上游提交和本地提交,进行一些比较并确定哪个是最后一个本地提交,即在git log时出现,并且也存在于上游,但是提供了一个git命令,此信息将非常方便。

Most of the time that would be 大多数时候

git merge-base origin/master master

(substituting whatever branch name for master ). (用分支名称代替master )。

The major exception would be if either the local or remote branch has been rewritten, so that they don't have any common commits. 主要的例外是本地或远程分支已被重写,以使它们没有任何公共提交。 (Well... they'd still have common history probably, but nothing you'd think of as "part of' the branch.) In that case, there's not a good answer other than to eyeball it. (嗯……他们可能仍然有共同的历史,但是您不会把它视为分支的“一部分”。)在这种情况下,除了关注它之外,没有什么好答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM