Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git reflog a specific branch?

Tags:

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?

like image 761
Asim K T Avatar asked Oct 24 '16 04:10

Asim K T


People also ask

What is branch Reflog?

The 'reflog' command keeps a Reference logs such as the commit snapshot of when the branch was created or cloned, checked-out, renamed, or any commits made on the branch are maintained by track of every single change made in the references (branches or tags) of a repository and keeps a log history of the branches and ...

What is git Reflog?

Reflog is a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it. Basically every action you perform inside of Git where data is stored, you can find it inside of the reflog.

How can you restore a branch you just deleted?

To restore the branch, select the ... icon next to the branch name and then select Restore branch from the menu. The branch will be recreated at the last commit to which it pointed. Note that branch policies and permissions will not be restored.

How can I clear up a git Reflog?

git reflog expire --expire-unreachable=now --all removes all references of unreachable commits in reflog . git gc --prune=now removes the commits themselves. Attention: Only using git gc --prune=now will not work since those commits are still referenced in the reflog. Therefore, clearing the reflog is mandatory.


1 Answers

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

like image 119
torek Avatar answered Sep 16 '22 17:09

torek