Search code examples
gitgit-log

Where do docs explain why "git log" output differs based on checked-out branch?


The output from git log is different based on what branch I currently have checked-out. Where in the git documentation does it explain this behavior?

I looked at git log --help and git rev-list --help but don't see anything explaining the that git log is context-sensitive based on which branch I have checked-out.

EDIT:
I had read the following section that @max and @James mentioned, and it's clear what happens when one of the commits is omitted and .. is specified. But it's ambiguous what happens when both commits are omitted. And it's also ambiguous when one commit is omitted and the .. is omitted:

<since>..<until>

Show only commits between the named two commits. When either <since> or <until> is omitted, it defaults to HEAD, i.e. the tip of the current branch.

So, for example, the following would be equivalent:
git log master.. is equivalent to:
git log master..HEAD

git log ..master is equivalent to:
git log HEAD..master

But, if both <since> and <until> are omitted, then what?
git log is NOT equivalent to:
git log HEAD..HEAD

So what is git log equivalent to in the <since>..<until> format?

And if only one commit is listed, but not .., then what?
git log foo equivalent to:
git log foo..HEAD or
git log HEAD..foo ?


Solution

  • Git log has an implied argument HEAD so when you do

    git log

    you are actually doing

    git log HEAD

    which means you will get the log from the tip of the current branch

    From Git Log Manual for since..until options

    Show only commits between the named two commits. When either or is >omitted, it defaults to HEAD, i.e. the tip of the current branch. For a more complete >list of ways to spell and , see gitrevisions(7).

    As per updated question the following should explain all the situations you stated

    From Git Revisions

    For example, origin.. is a shorthand for origin..HEAD and asks "What did I do since I >forked from the origin branch?" Similarly, ..origin is a shorthand for HEAD..origin and >asks "What did the origin do since I forked from them?" Note that .. would mean >HEAD..HEAD which is an empty range that is both reachable and unreachable from HEAD.

    If .. is omitted then it is just

    git log <rev>
    

    which include commits that are reachable from (i.e. ancestors of) rev. This is explained in git-rev-list who’s options are applicable to git-log as stated in the manual.