简体   繁体   中英

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.

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 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

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> . 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 . It's name will have format origin/network . To see last commit pushed there you may use git show origin/network . To rebase everything until this commit, try git rebase -i origin/network .

You can use --decorate

Example $ 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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