34

Why doesn't git log simply log all the latest commits?

And what does this mean?

--all
       Pretend as if all the refs in refs/ are listed on the command line as <commit>.

I assume, once translated into plain English, that it means show all the latest commits.

Can someone clarify.

Snowcrash
  • 80,579
  • 89
  • 266
  • 376
  • 5
    Thank you for asking this - I have "`log --all`" in some of my aliases, and I assumed that it meant "look in all branches, not just the current one" (which it seems is more or less correct), but I looked at the docs today just to be sure before telling someone else to use it. I read that sentence and thought "WTF?". – Michael Burr Feb 26 '19 at 23:26

4 Answers4

23

No, that doesn't mean it shows all the latest commits. It shows all commits in the history of branches, tags and other refs, but it does not show commits that are not reachable from any ref. A typical example of a commit that is not reachable from any ref is when you've just run git commit --amend: the previous commit still exists locally, but it's no longer reachable and won't be shown in git log --all. But git reflog will confirm that it does indeed still exist.

As for why --all isn't the default: you normally won't want that. For instance, if you're on branch master, and you run git log, you typically aren't interested in the history of any feature branches, you typically want to see the history of master.

If you do normally want the --all behaviour, I recommend creating an alias.

  • 1
    You clarified the things `--all` does *not* do and the real answer to the question is a bit hidden (through negation) in your second sentence. A bit hard to read for a non-native English speaker. And *if* I understood you correctly (my English also isn't that great, It's only my 3rd language...), it could be rewritten more succinctly as "git log --all shows all commits *reachable from any ref*". Would that be a correct understanding of your sentence? – exhuma Sep 10 '22 at 14:10
4

According to a post here git --all missing commit:

log --all is only for listing commits referenced in refs/ (like tags, heads, ...)

The same page also says:

The --all option does not tell git log to display all commits. It asks for the logs of all refs, basically your branches and tags.

Community
  • 1
  • 1
Bryan Green
  • 441
  • 3
  • 18
3

From page 68 of Scott Chacon and Ben Straub's Pro Git:

git log doesn’t show all the branches all the time. [...] by default, git log will only show commit history below the branch you’ve checked out. To show commit history for the desired branch you have to explicitly specify it: git log testing. To show all of the branches, add --all to your git log command.

So basically, without --all you only see the commits that actually make up your current branch.

Jan Berndt
  • 913
  • 1
  • 10
  • 22
1

Because wanting to see the history of all branches/etc. isn't as common when working as wanting to see the history of something specific, typically the current branch.

I assume, once translated into plain English, that it means show all the latest commits.

No. refs/ contains things like branches and tags. If you want to see the history of a particular branch, or a particular set of branches, you list them in your git log command. If you want to see the history of all branches/tags/etc., then you can use the --all shortcut.

Git log doesn't just show 'the latest commits': it shows all commits that fit the given criteria, of which there are several dimensions. E.g., what branches is the commit on, is the commit in a particular range, etc.

bames53
  • 86,085
  • 15
  • 179
  • 244