Last Updated: February 25, 2016
·
1.51K
· Harshniket Seta

Show git logs since last version change.

Let us assume you have a version file. As such this could be any file in your git repo. You just need to call this function below with folder name and the file. By giving a folder name if will show logs only related to that folder. The file is used as a benchmark. It basically looks when the file was last changed and takes its revision ID to get the logs since that revision ID.

function whatchanged() {        #what chnaged will give us the log of the     specified folder since the given file was last changed.$1=folder $2=file
for i in `git rev-list --all $2`
do
    git log $1 "$i.." 2>/dev/null
#   For one line messages.
#   git log "$i.." --format="%ad %an %s" 2>/dev/null 
    RET=$? 
    if [ $RET -ne 0 ]
    then
        echo "Nothing"
    fi
    break;
done

}

Thus, this way everytime you change your version the file will change and thus using the function below you can get the logs since the last version change.

Some examples:

whatchanged "" version.txt

The above call will give me the git log on the whole repo since the last time the version.txt file was changed.

whatchanged "client/" version.txt

The above call will give me the git log only the client/ folder since the last time the version.txt file was changed.

Please comment if you want to me to explain some parts in more detail.Also tell me if you have any other problems or ideas with git.

1 Response
Add your response

This is great!
I have an alias since before that creates nice one-line logs, that in my mind works great with this, so I'll just share:

In .gitconfig
[alias]
lol = log --graph --decorate --pretty=oneline --abbrev-commit

over 1 year ago ·