skweez.net

List the git repository changes during the last week

by ritze
17.07.2012

Today I hacked a little bit on a modify git command. I read the blog article List the modified files on your repository from Filipe Kiss and thought, I could improve his command.

The basis is this:

git whatchanged --since="1 week ago" --format=oneline | grep "^:" | \
sed 's:.*[DAM][ \\''t]*\([^ \\''t]*\):\1:g'

I want to see, if a file was modified, attached or deleted, therefore I left the letters M, A and D and, in addition to that, I replaced the tab after the letter with a space:

git whatchanged --since="1 week ago" --format=oneline | grep "^:" | \
sed ''/.*A\\t/s::A\ :g'' | \
sed ''/.*M\\t/s::M\ :g'' | \
sed ''/.*D\\t/s::D\ :g''

But we live in the year 2012, so we need color:

git whatchanged --since="1 week ago" --format=oneline | grep "^:" | \
sed ''/.*A\\t/s//`printf "\033[33mA\033[0m"`\ /'' | \
sed ''/.*M\\t/s//`printf "\033[32mM\033[0m"`\ /'' | \
sed ''/.*D\\t/s//`printf "\033[31mD\033[0m"`\ /''

I don't want to see duplicate entries. The next is to delete the duplicate entries:

git whatchanged --since="1 week ago" --format=oneline | grep "^:" | \
sed ''/.*A\\t/s//`printf "\033[33mA\033[0m"`\ /'' | \
sed ''/.*M\\t/s//`printf "\033[32mM\033[0m"`\ /'' | \
sed ''/.*D\\t/s//`printf "\033[31mD\033[0m"`\ /'' | \
awk '!x[$0]++'

This method has one problem: The list could have two or even three entries of one file. One for modifiy, attach and delete. If you prefer to see only the latest action on this file, you can use awk '!x[$2]++' instead of the last awk command.

Now we only have to sort the list without being considerate to the action on the file:

git whatchanged --since="1 week ago" --format=oneline | grep "^:" | \
sed ''/.*A\\t/s//`printf "\033[33mA\033[0m"`\ /'' | \
sed ''/.*M\\t/s//`printf "\033[32mM\033[0m"`\ /'' | \
sed ''/.*D\\t/s//`printf "\033[31mD\033[0m"`\ /'' | \
awk '!x[$0]++' | sort --key=2

The command executed on my parser branch: