git log for specific commit in branch

I was searching a certain commit id in a specific branch, although the commit isn't in that specific branch I've got a result, while in git log there are no results.

git log commit_id # finds commit

git check a # branch 'a' doesn't contain commit_id

git log # search for commit_id with no results.

is that a bug or by design? if not a bug, then why?

Thanks in advance.

Answers

git log is the list of commits in that specific branch, it's not a bug. If you just run git log without the <sha1> it'll show the commits in reverse order for that particular branch.

If you want to view a commit, you can use git show <sha1> to view that particular commit, which isn't branch specific.

You need to remember that branches are just references to commits. Meaning if you say git log <branch>, you are actually saying git log <commit to which this branch points>. And with that, git goes to that commit(or branch which is just a pointer) and shows history from there.

If you call git log <commit_id>, it makes no difference. git still goes to that commit and starts log from there.

I'll repeat again for your understanding, branch is just a pointer. They exist just to make our lives easier and are not at all necessary. Git is only interested in commits they point to.