3

Is there any way to configure the default number of commits that will be returned by git log? I know you can do git log -5 to get the last 5 commits, but what if I forget and just do git log? I have several aliases for git log and would like them all to return something like the last 100 commits unless I specify something else specifically.

Ideal situation assuming I have git ls setup as an alias:

git ls returns the last 100

git ls -5 returns the last 5

It would be really great if I could to something like git ls -0 to disable the default and return everything.

Is any of this possible or should I consider this my first draft for a feature request to the Git team?

AdmSteck
  • 1,753
  • 15
  • 25

2 Answers2

2

If you supply more than one count, the last one takes precedence. For example, git log -2 -1 shows only one result.

So you can supply a default parameter in your alias definition and optionally override it when you run the command.

Regarding using -0 to return everything, just use -9999999 or similar instead.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
0

For anyone looking at this recently, I tried to do what the accepted answer says but can't get it to work, and found a more recent answer saying you can't name an alias after a built-in git command anymore: https://stackoverflow.com/a/11226146/14587004.

For anyone wondering how to get close enough, I did

git config --global alias.ls 'log -100'

to get the git ls alias to work how the OP puts it. I also added the --oneline flag to mine, which I think is nice to know about. The git config command edits the ~/.gitconfig file, so you can edit it manually with a text editor too if you want. You would append

[alias]
    ls = log -5

to the file.

Eric Pedley
  • 103
  • 9