Foreword
We can usegit 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 ofdate
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 entergit t
in the git repo to replace the long git subcommands. < 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.
No Comment
Post your comment