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


gitlab,reset password

reset gitlab password

The gitlab built with docker has been useless for a long time, and I forgot the password, how to reset it. ​​​​​​We should be able to enter the gitlab container through the following command...

git

Display your own version control through the git command, for example, within 7 days?

How to display your own version control through git commands? These commands are for reference only, at least the author name should be changed. --author parameter, can also be mailbox

git

How do I delete a remote branch on my GitHub

How do I delete my remote branch on GitHub. First of all, you can use the command to view the origin git remote -v At this time, it may display as follows: origin https://github.com/DevinY/dlaravel.git (fetch) ​​​​​​​​origin https://github.com/DevinY/dlaravel.git (push)