Let Git output multiple colors and custom log formats

Source: Internet
Author: User
Tags iso 8601 iso 8601 format hex code

Let Git output multiple colors and custom log formats
Git multi-color output

Git outputs a single color by default, which is not only beautiful but not easy to read. In fact, Git itself supports multiple colors to display its output information. You only need to run the following command in the command line to modify git settings to enable multi-color output:

git config --global color.status autogit config --global color.diff autogit config --global color.branch autogit config --global color.interactive auto

After the above commands are executed, the output of the git status, diff, branch, and other commands will all be colored. See the example.

Custom log format

After completing the preceding steps,git logAlthough the command output has a certain color, it is still boring (SEE ).

It doesn't matter. The powerful git provides the function to customize the log format. Try to enter the following command:

git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

You will see similar output:

How are you doing? However, it is unrealistic to output such a long string of commands every time you view logs. Let's solve this problem through the git command alias. Enter the following command:

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"

The preceding command creates a command alias.lgEvery time you use the commandgit lgIt is equivalent to entering the long string of commands. Now, if you want to see the beautiful multi-color output, usegit lgTo view common log output, usegit log.

If you want the log to output some specific information, you can adjust it by yourself.--prettyParameter value. For example, the following command only displays the commit hash, submission time, And submitter Name:

git log --pretty=format:'%h %ar %an'

You can replace the content in the single quotes following the format with the desired format to implement a custom log output format. Here%h,%arAre some pre-defined placeholders of git. The complete list is as follows:

% H Commit hash
% H Short hash of commit
% T Tree hash
% T Short hash of tree
% P Parent hashes
% P Parent short hashes
% Author name
% The author name in mailmap (. mailmap, For details, refer to git-commit log (1) or git-blame (1 ))
% AE Author email
% AE Email Address of the author (. mailmap. For details, refer to git-commit log (1) or git-blame (1 ))
% Ad Date (-date = the specified format)
% AD Date, RFC2822 format
% Ar Date, relative format (1 day ago)
% Date, UNIX timestamp
% Ai Date, ISO 8601 format
% Cn Submitted by name
% CN Name of the submitter (. mailmap. For details, refer to git-commit log (1) or git-blame (1 ))
% Ce Submitted by email
% CE Submitted by email (. mailmap, For details, refer to git-commit log (1) or git-blame (1 ))
% Cd Submission date (-date = the specified format)
% CD Submission date, in RFC2822 format
% Cr Submission date, in the relative format (1 day ago)
% Ct Submission date, UNIX timestamp
% Ci Submission date, in ISO 8601 format
% D Ref name
% E Encoding
% S Commit information title
% F Filter the title of the commit information so that it can be used as a file name
% B Commit Information Content
% N Commit notes
% GD Reflog selector, e.g., refs/stash @ {1}
% Gd Shortened reflog selector, e.g., stash @ {1}
% Gs Reflog subject
% Cred Switch to red
% Cgreen Switch to green
% Cblue Switch to blue
% Creset Reset color
% C (...) Set the color, as described in color. branch. * config option
% M Left, right or boundary mark
% N Line feed
% A raw %
% X00 Print a byte from a hex code
% W ([<w> [, <i1> [, <i2>])

Ubuntu perfectly installs and builds a Git Server

GitHub Tutorials:

GitHub tutorials

Git tag management details

Git branch management

Git remote repository details

Git local Repository (Repository) Details

Git server setup and Client installation

Git Overview

Share practical GitHub tutorials

How to Build and use Git servers in Ubuntu

Git details: click here
Git: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.