mergestat-lite
mergestat-lite copied to clipboard
Finding file paths affected by a commit
I've been trying to work out how to filter file paths affected by a specific commit. Or in other words, show me the files modified by a particular commit, or maybe all the files affected when a particular merge happens.
As far as I can tell, each commit hash in the files
table has a record for every file in the tree at that time. I'm struggling to see where in the data model the file paths changed in each commit might be available.
Thanks!
Hi @eddiesholl - I think what you're asking about can be achieved using the stats
table-valued function. For instance:
SELECT * FROM commits, stats('', commits.hash)
Will return the stats (additions
/deletions
) for every file modified in a commit. In this case, since you mainly are looking for the files modified, the stats
name is a bit misleading, but the query will give a list of the file paths modified by the commit (and you can ignore the "stats").
SELECT * FROM stats('', 'some-commit-sha')
Will return results only for a known commit hash.
SELECT * FROM commits, stats('', commits.hash)
WHERE commits.parents > 1
Will return stats only for merge commits (a commit with more than 1 parent).
Hope that helps!