简体   繁体   中英

git reflog shows me commits unrelated to my branch. How do I get the commits related to the branch I have checked out?

I accidentally committed and merged some work into another branch when I wasn't meant to. To fix this I need to go back to an earlier commit.

However, when I run git reflog I get a list of commits relating to another branch I am working on. None of them are related to the branch I am currently working on and have checked out now.

Would anyone know why this is and how I could find the commits relating to my branch?

If you still have your branch, use : git reflog [yourbanch]

If you look for the history of otherbranch : git reflog [otherbranch]


git reflog , which is a shortcut for git reflog HEAD , give you a detailed history of all checked out commits ; this is useful in general (it makes for a great undo stack), but is indeed more noisy.

The format you're using when you do a simple git reflog is

git reflog [show] [log-options] [<ref>]

so you're in fact omitting two arguments, which will be assumed and fall back to their defaults :

git reflog show HEAD

which ouputs a history of HEAD itself, so a list of actions on (provided you do have a multiple branches workflow) a mix of different branches.

But you could have specified a branch (EVEN IF the branch happens to already be checked out, since HEAD won't be resolved to the current branch here) :

git reflog some-feature

(here, the show action is also implied but the branch is explicit)


From the doc :

The "show" subcommand (which is also the default, in the absence of any subcommands) shows the log of the reference provided in the command-line (or HEAD, by default).

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