Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git how to save a preset git log --format

I really like the short git log format where I can see author, date and change description like this:

git log --pretty=format:"%h%x09%an%x09%ad%x09%s" 

Which outputs:

  fbc3503 mads    Thu Dec 4 07:43:27 2008 +0000   show mobile if phone is null...      ec36490 jesper  Wed Nov 26 05:41:37 2008 +0000  Cleanup after [942]: Using timezon   ae62afd tobias  Tue Nov 25 21:42:55 2008 +0000  Fixed #67 by adding time zone supp   164be7e mads    Tue Nov 25 19:56:43 2008 +0000  fixed tests, and a 'unending appoi 

(from stackoverflow question "link text")

Now, the question is, how do I save this as a new format on my machine so I only have to write something like, for instance:

git log --format=jespers_favourite 
like image 308
Jesper Rønn-Jensen Avatar asked Sep 17 '09 20:09

Jesper Rønn-Jensen


People also ask

What is git log -- Oneline?

Git Log Oneline The oneline option is used to display the output as one commit per line. It also shows the output in brief like the first seven characters of the commit SHA and the commit message.

What is git log command?

The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA)

Does git log show all branches?

Many times it's useful to know which branch or tag each commit is associated with. The --decorate flag makes git log display all of the references (e.g., branches, tags, etc) that point to each commit.


2 Answers

In newer versions of Git (confirmed with v1.7.8) it is possible to set named pretty-print log formats using git config pretty.named_format. These can be set at a machine-wide, user or file level with the <file-option> argument.

To create a log format called jespers_favourite or the whole machine use --system

git config --system pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s" 

For single user use '--global'

git config --global pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s" 

Leaving the <file-option> argument blank will default to setting the config file of the current repository, .git/config unless defined otherwise.

like image 117
tdbit Avatar answered Oct 05 '22 10:10

tdbit


Considering the git log manual page mentions:

--pretty[=<format>] --format[=<format>] 

Pretty-print the contents of the commit logs in a given format, where can be one of oneline, short, medium, full, fuller, email, raw and format:. When omitted, the format defaults to medium.

the <format> can only have predefined values.
That only leaves you the possibility to define an alias as a shortcut for that command.

[alias]         jespers_favourite = log --pretty=format:"%h%x09%an%x09%ad%x09%s" 

or

[alias]         compactlog = log --pretty=format:"%h%x09%an%x09%ad%x09%s" 
like image 26
VonC Avatar answered Oct 05 '22 10:10

VonC