Shell script case: Get your own git commit record last week

Background
The daily work weekly report needs to summarize the main work of the past week, which requirements were developed and which bugs were solved. It is more objective to present it through the git submission log. This article introduces how to use the shell to call the git command to obtain your own git submission record last week.

The analysis
script involves several key points:

Get submission author information: read git config to get the author;
get the date of the day and a week ago: use the date command to get it;
get git submission records within a certain date range: use the git log command to get it;
the script
can be used directly on mac systems:

#!/bin/bash
function isMacOS() {   # The date command under Mac is BSD (Berkeley Software Distribution) system,   # The date command under Linux is GNU (GNU's Not Unix) system. There are some differences in the usage of the two.   # BSD does not specifically specify any BSD derivative version, but a general term for a branch of a UNIX-like operating system.   # Mac OS X and iOS are actually based on Darwin, which is a branch of BSD.   uNames=$(uname -s)   osName=${uNames: 0: 4}   if [ "$osName" == "Darw" ] # Darwin, AKA "Mac OS X"   then     echo 0   elif [ "$osName" == "Linu" ] # Linux, AKA "GNU/Linux"   then     echo 1   elif [ "$osName" == "MING" ] # MINGW, windows,




















author_name=$(git config -l|grep user.name=|cut -c11-)
if [ -z "$author_name" ]; then
  echo "[ERR]: Can not determine username for git, please check user.name"
  exit 1
fi

now_date=$(date +%Y-%m-%d)
if [ "$is_mac" ];
then
  # Mac , through the -v parameter, -v-1d represents the previous day, -v-1y represents the previous year
  last_week= $(date -v-7d +%Y-%m-%d)
else
  # Linux, through the –date parameter solid line, –date="-1 day" represents the previous day, --date="-1 year" represents the previous day year
  last_week=$(date -date="-7 day" +%Y-%m-%d)
fi
git log --oneline --since="$last_week" --until="$now_date" --author ="$author_name" | awk '{ print $2$3}'

1
2
3
4
5
6 7
8
9
10
11
12
13
14
15
16
17
18
19 20
21
22
23
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39The knowledge points of the article match the official knowledge files and can be further Learn related knowledge —————————————— Copyright statement: This article is an original article by CSDN blogger “csfchh” and follows the CC 4.0 BY-SA copyright agreement. Please attach a link to the original source for reprinting and this statement. Original link: https://blog.csdn.net/csfchh/article/details/129696111




















Guess you like

Origin blog.csdn.net/u012294613/article/details/132432610