gitgit-loggitlist

How to list all files those don't change since a specific GIT commit


There is a big commit long ago in the past and a lot of change happened since then. How do I list all files those don't change of that commit up to now?


Solution

  • You can use the following command chain:

    git ls-files | grep -v "$(git diff --name-only <from-commit> <to-commit>)"
    

    git ls-files lists all files which are under version control, while git diff --name-only <from-commit> <to-commit> will list the files which got changed in the specified commit range.

    grep -v returns all lines which don't get matched by the given pattern (inverse match).

    Hope that helps!


    If you have problems with an Argument list too long error then you can use the following shell script:

    #!/bin/bash
    
    git diff --name-only $1 $2 | {
        files="$(git ls-files)"
    
        while read line
        do
            files=$(echo "$files" | grep -v $line)
        done
    
        echo "$files"
    }
    

    This script will exclude one file path per iteration from the list of all files, so you should never experience the Argument list too long error.

    You can use the script by saving it into a file and execute it with the commit hashes of the commit range whose files should be excluded from the result.