Search code examples
gitgithubgit-log

How to get ONLY filename with path using git log?


I used almost all git log commands yet i haven't found a best way to do this. I need only this - get only file name with path nothing else

/path/filename.txt
/path/anotherfile.ext
...
...

My input is date FROM and TO to the git log command. Either git log gives developer-name or date or commit-number or something that i don't want with file names. How to get ONLY the file name with full path?


Solution

  • Use the --since and --until options to select the time range and then you can use UNIX pipes to grep, sort and collect the uniqe paths:

    git log --name-status --since='..' --until='..' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'
    

    Example:

    git log --name-status --since='1 January 2015' --until='2 January 2015' | grep -E '^[A-Z]\b' | sort | uniq | sed -e 's/^\w\t*\ *//'
    

    For more detailed git log outputs see How to have git log show filenames like svn log -v


    If you have two commit hashes, you can also use git diff and --name-only instead, as the other answer mentions:

    git diff hash1..hash2 --name-only