I'm trying to get a list of only new directories using git diff (or something else).
I can get a list of new files, or show only directories, but a file can be added to a directory that already exists.
Any ideas?
I'm trying to get a list of only new directories using git diff (or something else).
I can get a list of new files, or show only directories, but a file can be added to a directory that already exists.
Any ideas?
git ls-tree provides part the information you need, but you'll need to use a regular diff to extract the actual diff.
This is not a fully satisfying answer, but you can use git ls-tree to show the contents of a commit, and with the right options reduce that to just the list of directories that commit includes.
Here's the logic behind my solution:
git ls-tree -r -t <commit> outputs lines with blob for each file, and tree for each directory.grep " tree " to see just the trees, i.e., the directories.So, to see the list of directories in a commit:
git ls-tree -r -t <commit> | grep ' tree ' | sed 's/.*\t//'
And now diff the output of that command for the two commits. This bash command line will work interactively, but it's ugly:
diff <(git ls-tree -r -t <commit1> | grep " tree " | sed 's/.*\t//') <(git ls-tree -r -t <commit2> | grep " tree " | sed 's/.*\t//')
To make this solution usable, I would turn it into a script. Let's call it git-new-dirs:
#!/bin/bash
commit1=$1
commit2=$2
diff <(git ls-tree -r -t "$commit1" | grep " tree " | sed 's/.*\t//') <(git ls-tree -r -t "$commit2" | grep " tree " | sed 's/.*\t//')
If you put that script somewhere on your PATH, you will then be able to use it by typing
git new-dirs <commit1> <commit2>