Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.4k points)

I know that a git commit changed multiple files in the directory src/java/task

It wants to list all files in that directory that were not changed as part of that commit.

Real-world context: I'm reviewing changes by someone and believe they should have made a similar change to every file in that directory. I want to know any files they didn't change in their commit (that may have been missed, or actually didn't need changing but I want to examine why).

1 Answer

0 votes
by (41.4k points)

Try this:



# all files under src/java/task/, excluding subfolders

all=$(git ls-tree ${commit}:src/java/task | awk '/ blob /{print "src/java/task/"$4}')

# files changed by the commit

changed=$(git show ${commit} --pretty= --name-only)

# files not changed by the commit

for f in ${all} ${changed} ${changed};do

    echo ${f}

done | sort | uniq -u

Suppose the script is, the repository is at /path/to/foo/, and the commit is HEAD. To run the script,

GIT_DIR=/path/to/foo/.git bash HEAD

There may be a git command with some magic options to do the job, but I can't find any yet.

Check out this Git Tutorial to know more.

Related questions

Browse Categories