You can indeed use git reflog
to check if there's a missing commit on a remote branch, but it will only work if you have an up-to-date copy of that remote branch in your local repo (your remote-tracking branch).
You can keep your local remote-tracking branch up-to-date by frequently running git fetch
. However, if someone pushes a commit that you haven't fetched and then later deletes it before your next fetch, then you're not going to know that there was a commit that was deleted. You'll only find out that the remote branch's history has been altered if you have a copy of the original history that has been changed, in which case Git will tell you that there has been a forced-update:
$ git fetch origin
From c:/Users/Keoki/Documents/GitHub/bare
+ 02f0d6e...5c7b77b master -> origin/master (forced update)
If someone has been force-pushing to your remote, it should be blatantly obvious as soon as you fetch or pull, because it will show up as a forced-update (as I've pointed out), unless you don't fetch or pull from your remote frequently. If you have direct access to your remote repo, you could check the reflogs directly on it as well.
Reflog Usage
You mention,
It looked like the man page for this says that this command can also be used to delete entries from the log which well kind of sucks.
git reflog
will only delete entries from the reflog (not the same log you get with git log
) if you pass any of the following extra options (from the official documentation):
Otherwise, git reflog
is read-only, and will just list the history of where your references has been. For your particular example, you can see the reflog history of your remote-tracking branch by using:
git reflog <remote>/<branch>
For example,
$ git reflog origin/master
5c7b77b refs/remotes/origin/master@{0}: fetch origin: forced-update
02f0d6e refs/remotes/origin/master@{0}: fetch origin: fast-forward
fc32eac refs/remotes/origin/master@{1}: pull origin master: fast-forward
b6a06e1 refs/remotes/origin/master@{5}: fetch origin: fast-forward
35a91e4 refs/remotes/origin/master@{6}: update by push
019ea3a
In the example above, you'll see the origin/master
was force-updated in the most recent (top) entry of the reflog, indicating that the original history of the remote branch has been altered, possibly indicating that a commit has been deleted (though rewritten commits will also cause forced-updates).