Git找到第一个非本地提交

标签 git git-rev-parse

相关:List Git commits not pushed to the origin yet

git rev-parse HEAD 为我提供了工作区中的最新提交,但这可以是本地提交的 githash。换句话说,一个尚未推送到远程的提交

如何在工作区的远程中找到也存在的最新提交

最佳答案

要获取当前 checkout 分支的已配置远程分支的最新提交,请执行以下操作

# first get your remote-tracking branches up-to-date with remote
git fetch

# then do
git rev-parse @{upstream}
# or even just
git rev-parse @{u}

(注意:@{upstream}/@{u}不是占位符,它们应该按原样输入)

来自 doc :

[<branchname>]@{upstream}, e.g. master@{upstream}, @{u}
The suffix @{upstream} to a branchname (short form @{u}) refers to the branch that the branch specified by branchname is set to build on top of (configured with branch..remote and branch..merge). A missing branchname defaults to the current one.

关于Git找到第一个非本地提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68554761/

相关文章:

git - 使用 git rev-parse <tag> 的错误提交哈希

git - 如何列出 github 存储库中的所有文件以及最后的编辑者和日期?

git - 如何将新的(重写的)历史推送到远程存储库

javascript - Git 子模块、切换分支和包含外部 JS 依赖项的推荐方式(天哪)

macos - 尝试克隆 Stash 存储库时出现 SSL 错误

django - 如何将大型 Django 项目划分为子项目进行扩展?

git - 使用 :/syntax 时引用匹配提交的父级