How to know if latest commit to master has been pushed to the remote?

I have merged a branch in to master and now I can see that in my git log

Some time has passed and now I want to know whether I previously also pushed master (with that commit) to the remote. How can I tell if it has been pushed?

I can think of a few workaround such as recloning the repository elsewhere, or resetting and checking and then re-merging but I feel that there's probably a somewhat simpler answer.

fyi this is different from How can I know in git if a branch has been already merged into master? as I know it has been merged, just don't know about the remote push.


Do

> git status

If the output is

# On branch master
nothing to commit, working directory clean

Then you have pushed the current commit.

If the output instead begins with

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#   (use "git push" to publish your local commits)

Then you have a local commit that has not yet been pushed. You see this because the remote branch, origin/master , points to the commit that was last pushed to origin. However, your branch is ahead of 'origin/master' , meaning that you have a local commit that has been created after the last pushed commit.

If the commit you are interested in is not the latest, then you can do

> git log --decorate --oneline

to find out if the commit in question is before or after the commit pointed to by origin/master .
If the commit is after (higher up in the log than) origin/master , then it has not been pushed.


If you have made multiple commits and not sure which one of them have been pushed to remote, try this:

git log origin/<remote-branch>..<local-branch>

Example:

git log origin/master..master

This would list out all commits in your local branch that have not been pushed to the remote branch mentioned.


I suggest you run this:

$ git fetch --all
Fetching origin
Fetching upstream

This will fetch the latest data from all remotes.

Then you run:

$ git branch -v
  master       ef762af [ahead 3] added attach methods
* testing      4634e21 added -p flag
  upstream     1234567 [ahead 1, behind 7] updated README.md

This will show which branches you're ahead or behind on.

I posted this because none of the other answers mention fetching the remote data, that step is crucial.

链接地址: http://www.djcxy.com/p/26048.html

上一篇: 如何做Git日志只看到合并到主分支?

下一篇: 如何知道是否已将最新的主人推送至远程?