简体   繁体   English

Git 找出我推送的最后一个提交

[英]Git find out the last commit i pushed

I want to find out the last thing that I pushed, not the last thing i commited, but pushed.我想找出我推送的最后一件事,不是我提交的最后一件事,而是推送的。

Is there a git command for this?是否有为此的 git 命令?

Context: I want to squash some commits before merging my dev_branch with a master branch but I have been told you can not rebase anything that is already pushed (is this true?).上下文:我想在将我的 dev_branch 与 master 分支合并之前压缩一些提交,但我被告知你不能重新设置已经推送的任何内容(这是真的吗?)。

So i would like to know what was the last commit that I cannot include in this rebase.所以我想知道我不能包含在这个 rebase 中的最后一次提交是什么。

If you mean the last commit you pushed to the master branch then, assuming your remote is origin : 如果你的意思是你推到master分支的最后一次提交,那么假设你的遥控器是origin

git rev-parse origin/master

This will show you the commit ID of the tip of the master branch of the origin origin, as your local repository is currently aware. 这将显示origin源的master分支的提示的提交ID, 因为您的本地存储库当前知道。 This may mean that the commit is someone else's commit, if someone else pushed commits after you did and you have since fetch ed that branch. 这可能意味着提交是其他人的提交,如果其他人在您执行后推送提交,并且您已经fetch该分支。

git show -p origin/master

This command will give you information about the commit, including the commit ID, author, log message, and diff to its parent commit(s). 此命令将为您提供有关提交的信息,包括提交ID,作者,日志消息和对其父提交的差异。


One of my favorite Git commands for doing exactly this kind of inspection: 我最喜欢的Git命令之一就是进行这种检查:

git log --pretty=oneline --abbrev-commit --graph --decorate --all

This will display a nice ASCII-art graph of the commit history, and each commit will show any refs that are targeting it. 这将显示提交历史记录的一个很好的ASCII艺术图表,每个提交将显示任何针对它的引用。 This way you can, at a single glance, see branches and merges in history and easily see where origin/master is in relation to your own master . 通过这种方式,您可以一目了然地查看历史记录中的分支和合并,并轻松查看origin/master与您自己的master

The correct command to find the commit you could squash against is:找到可以压制的提交的正确命令是:

git rev-parse @{push}

That command will error out if your repository has no commits, or your repository has no remote to push to.如果您的存储库没有提交,或者您的存储库没有远程推送到,该命令将出错。

If the result is equal to git rev-parse HEAD (which will also fail if your repository has no commits), then you have nothing to squash.如果结果等于git rev-parse HEAD (如果您的存储库没有提交,它也会失败),那么您没有什么可压缩的。

You can get a list of squashable (not-yet-pushed) commits via git log @{push}..HEAD .您可以通过git log @{push}..HEAD获取可压缩(尚未推送)提交的列表。

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

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