by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 years ago )

Foreword

We can use git config --global alias.[alias] "to reduce the long and often executed git subcommands"  into simplified aliases.
So you can also add your frequently used git commands to the global git alias through the git alias setting.

Let's take a look at my practical example of how to reduce long subcommands into easy-to-use aliases.

Example:

On MacOS , since the command of date is different from that of Linux , two versions of setting methods are provided.
Copy and paste the command below to the terminal to complete the setting.
Then we can go to the git REPO to test the results.
Input: git t (today's record)
Input: git y (yesterday's record)
MacOS:
git config --global alias.y "log --pretty=format:'%h - %an, %ar : %s' --since \"$(date -v - 1d +'%Y-%m-%d 00:00:00')\" --until \"$(date -v -1d +'%Y-%m-%d 23:59:59')\ "--stat"
git config --global alias.t "log --pretty=format:'%h - %an, %ar : %s' --since \"$(date +'%Y-%m-%d 00:00 :00')\" --until \"$(date +'Y-%m-%d 23:59:59')\" --stat"

Linux:
git config --global alias.y "log --pretty=format:'%h - %an, %ar : %s' --since \"$(date -d " yesterday" +'%Y-%m-%d 00:00:00')\" --until \"$(date -d "yesterday" +'%Y-%m-%d 23:59:59' )\" --stat"
git config --global alias.t "log --pretty=format:'%h - %an, %ar : %s' --since \"$(date +'%Y-%m-%d 00:00 :00')\" --until \"$(date +'Y-%m-%d 23:59:59')\" --stat"

Execution result

I just need to enter git t in the git repo to replace the long git subcommands.
git log< br /> If we want to see how to do the difference between these files, multiple -p parameters are enough.
Example: git t -p

Automation

If you want to automatically generate such a Git report, and send yesterday's results to the email every day,
You can take a look at my Python program on Github to help you get this done.
https://github.com/DevinY/git-yesterday-report

This is my first Python program after spending two days learning Python.
My impression of learning Python is that it is really a language with a gentle learning curve.
Even if you don't know Python, I think you can guess what I'm doing by reading the main.py in my github.

Tags: git

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


git

Forcibly clear all data in the remote repo

Forcibly clear all data in the remote repo

git

Remove the git remote or local tag

How to delete the Tag on the remote or local end of git.

git

Through the Git attribute, different codes such as big5 and gb2312 are normally displayed at the same time during diff

The problem of garbled characters in different Chinese encodings, here is an example, for example, what will be displayed when there are three php files with different encodings at the same time. Let's look at the results directly through git log -p, and we will find that there are unintelligible garbled characters....