Git reflog a specific branch?

Asim K T picture Asim K T · Oct 24, 2016 · Viewed 12.1k times · Source

Can I reflog a specific branch?

git reflog shows all history on the repo. But I want to check the history of one specific branch, say production. Is there a way to do that?

Answer

torek picture torek · Oct 24, 2016

As noted in the documentation, git reflog takes an action verb (called <subcommand>) and optional modifiers. The action defaults to show, and its optional modifier is the reference name to show.

The default is to show operations on HEAD. (Most, but not all, "everyday" commands operate on and/or through HEAD in order to operate on any other reference. Therefore the claim that git reflog shows all history is in fact false—but it does show most, which might be close enough.) This gives you an immediate and obvious answer to the question of showing operations applied to the specific branch-name production:

git reflog show production

As the documentation notes, git reflog show is an alias for git log -g --abbrev-commit --pretty=oneline, so you can also run:

git log -g --abbrev-commit --pretty=oneline production

to get the exact same output. The key switch here is -g, which directs git log to walk the given ref's reflog, rather than commits reachable from the commit to which the ref points.

(You can continue to leave out the show verb, since it's still the default, though for this case I would advise including it—for instance, if your branch is named show or expire the name will be mistaken for the verb!)