简体   繁体   English

如何使用命令行查看最后推送的提交

[英]How can I use the command line to see which commit was pushed last

I have been learning to use git rebase -i lately to clean up my commits before I push my changes. 在推送我的更改之前,我一直在学习使用git rebase -i来清理我的提交。

However, I find that I am doing git log , then checking the remote repo via web gui to see which commit was the last one I pushed, then manually working out how my commits that was so I can use 但是,我发现我正在做git log ,然后通过web gui检查远程repo以查看哪个提交是我推送的最后一个提交,然后手动计算我的提交是如此我可以使用

git rebase -i HEAD~[amount]

It seems pretty long winded to have to use a web gui to check which commit was the last one pushed* to the remote repo when everything else can be done in command line 似乎很长时间不得不使用web gui检查哪一个提交是最后一个提交*到远程仓库,当其他一切都可以在命令行中完成

Suggestions for a better work flow? 建议更好的工作流程?

* since the golden rule of rebasing is not to rebase commits already pushed to the repo * 因为重新定价的黄金法则不是已经推迟到回购的承诺

If you do git branch -a , you will see additional branches names, starting with remote/<remote-name> . 如果你执行git branch -a ,你会看到其他分支名称,从remote/<remote-name> Those are pointing to branches on the selected remote. 那些指向所选遥控器上的分支。 Now, the thing is, those can be used just like any other tag or branch name. 现在,问题是,那些可以像任何其他标签或分支名称一样使用。

For example, assume branch net that is set to push to remote origin branch network . 例如,假设分支net被设置为推送到远程origin分支network It's name will have format origin/network . 它的名称将具有格式origin/network To see last commit pushed there you may use git show origin/network . 要查看推送的最后一次提交,您可以使用git show origin/network To rebase everything until this commit, try git rebase -i origin/network . 要在确认之前重新设置所有内容,请尝试使用git rebase -i origin/network

You can use --decorate 你可以使用--decorate

Example $ git log --decorate 示例$ git log --decorate

This will tell you which tag or branch is on which commit in the log overview. 这将告诉您日志概述中哪个标记或分支在哪个提交上。

In your case you want to be looking for origin/master and/or origin/HEAD . 在您的情况下,您希望寻找origin/master和/或origin/HEAD They are colored red by default. 它们默认为红色。


I always use this command to get a compact and understandable overview of the log history: 我总是使用此命令来获得日志历史的紧凑且易于理解的概述:

$ git log --decorate --branches --graph --pretty="oneline" --abbrev-commit

It has some other nice parameters that help construct a clear overview. 它有一些其他很好的参数,有助于构建一个清晰的概述。 You don't have to use it, but you can try it. 您不必使用它,但您可以尝试它。 It might be very helpful, especially when you work with different branches who have a different history. 这可能非常有用,尤其是当您与具有不同历史记录的不同分支机构合作时。

In simple scenario's it looks like this (commit messages are substituted in this example) 在简单的场景中它看起来像这样(在这个例子中提交消息被替换)

* 9562f31 (HEAD -> master, origin/master, origin/HEAD) Added A
* 57b2de9 Added B
* 687e7d6 Added C
* 187aac7 Added D
* 1fc4a05 Added E

in your case the (origin/master, origin/HEAD would be a little further down, while master and HEAD might be at the top. 在你的情况下(origin/master, origin/HEAD会稍微向下,而masterHEAD可能在顶部。

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

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