Last active
May 19, 2022 11:38
-
-
Save muath-ye/4030685c88113cfff47d7708359f6569 to your computer and use it in GitHub Desktop.
Export GIT LOG into an Excel file with headers and custom date if needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Export Git log into an excel file. | |
```bat | |
git log --date=local --pretty=format:'%h, %an, %ad, "%s"' >> log.csv | |
``` | |
> Export Git log into an excel file with headers. | |
```bat | |
echo sha, contributor, date, message > log.csv && git log --date=local --pretty=format:'%h, %an, %ad, "%s"' >> log.csv | |
``` | |
> Get Git log after a date time. | |
git log --after='2017-07-01 00:00:00' | |
> Get Git log before a date time. | |
git log --before='2017-07-01 00:00:00' | |
> Get Git log after a date time. | |
git log --after='2017-07-01 00:00:00' | |
============================================== | |
> Number of commits last month | |
```bat | |
# me, trying to explain this, SQL-style | |
git log | |
--author="$(git config user.name)" # I only care about my commits | |
--no-merges # ignore merge commits | |
--before=$(date "+%Y-%m-01T00:00") # before 2016-03-01T00:00 | |
--after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") # subtract +%d days and 1 month from the current date i.e. 2016-01-31T23:59 | |
--reverse # arrange commits oldest to newest | |
| grep commit # save the lines containing the word "commit" | |
| wc -l # and count them | |
# one-line version | |
git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse | grep commit | wc -l | |
# add it to your git aliases | |
git config --global alias.clm '!echo $(git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse | grep commit | wc -l) commits last month' | |
# enjoy | |
git clm | |
11 commits last month # I kinda' slacked off... | |
``` | |
============================================ | |
> Number of files changed, insertions, deletions | |
```bat | |
git log | |
--author="$(git config user.name)" | |
--no-merges | |
--before=$(date "+%Y-%m-01T00:00") | |
--after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") | |
--reverse | |
--stat # show the files changed, insertions, deletions line | |
| grep -Eo "[0-9]{1,} files? changed" # keep the "x file(s) changed" part of each commit | |
| grep -Eo "[0-9]{1,}" # keep the numbers | |
| awk "{ sum += \$1 } END { print sum }" # add them together | |
# one-line version | |
git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse --stat | grep -Eo "[0-9]{1,} files? changed" | grep -Eo "[0-9]{1,}" | awk "{ sum += \$1 } END { print sum }" | |
# add it to your git aliases | |
git config --global alias.flm '!echo $(git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse --stat | grep -Eo "[0-9]{1,} files? changed" | grep -Eo "[0-9]{1,}" | awk "{ sum += \$1 } END { print sum }") files changed last month' | |
# enjoy | |
git flm | |
17 files changed last month | |
# insertions and deletions are identical i.e. | |
git config --global alias.ilm '!echo $(git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse --stat | grep -Eo "[0-9]{1,} insertions?" | grep -Eo "[0-9]{1,}" | awk "{ sum += \$1 } END { print sum }") insertions last month' | |
git ilm | |
242 insertions last month | |
git config --global alias.dlm '!echo $(git log --author="$(git config user.name)" --no-merges --before=$(date "+%Y-%m-01T00:00") --after=$(date -d "-$(date +%d) days -1 month" "+%Y-%m-%dT23:59") --reverse --stat | grep -Eo "[0-9]{1,} deletions?" | grep -Eo "[0-9]{1,}" | awk "{ sum += \$1 } END { print sum }") deletions last month' | |
git dlm | |
9 deletions last month | |
``` | |
See : https://helpfulsheep.com/2016-03-22-what-git-i-do-last-month/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment