tags:

views:

84

answers:

1

Hi,

I have to generate a list of changes in a git repository over a priod of time. For this, I have noted the commit ID and compare it with the recent HEAD to generate the list of changes in a git repository. For e.g:

$ git diff --name-status OLD_COMMIT..HEAD

This gives a list of modifications in a git repository.

But, recently I noticed a flaw in this approach as it doesn't list out the directory deleted. Though it lists out the deleted files correctly.

How can I get a correct list of deletions in a git repository? (As, if it could list the deleted directory, so it is understood that all the files have been deleted inside it. Hence there won't be a huge list of deleted files but a single line showing the deleted directory!!!)

+4  A: 

git does track tree objects which are its representation of directories. Although technically possible from an object model standpoint, git doesn't keep trees that are empty. Instead, git will remove any entry for an empty tree from its parent tree.

The command git diff-tree produces an output that shows how all tree entries have changed between to trees.

git diff-tree origin/master master

This will output how all entries in the given tree (i.e. the root tree of the given commit in this example) have changed.

The format is described in the git-diff-tree man page, but basically any directory that has been created or removed will have 040000 in the second or first column and 000000 in the first or second column respectively. This are the tree entry 'modes' for the left and right entries.

If you want to recurse and look for tree entries in sub-trees you must use the -t option and not just the -r options as by default -r shows a tree's sub-entries instead of the tree entry itself, -t will show both.

If you are interested in directories that have changed (added or deleted, or changed to or from another type - e.g. symlink) and not just different contents then you probably need to filter out entries which start :040000 040000.

Here's a possible command line that does that.

git diff-tree -t origin/master master | grep 040000 | grep -v -E '^:040000 040000'
Charles Bailey