I want to find the last commit that touched each file that ever existed on a set of branches. That is, for each file that ever existed on one or more of the specified branches, give me the last commit that touched it.
That commit could have added the file, modified the file, deleted the file, etc. I need the commit hash but it would be nice to generate the file status from the commit (A,M,D,etc.), the set of branches that reach it and the commit date with the same command so I don't have to go run more commands to generate it. I doubt I can get all of that in one go but that's the ultimate set of information I need.
I know how to get a list of files ever in the repository but not how to reduce that to the set of files that ever existed on a set of branches. Even if I generated a file list it seems inefficient to generate that and then go back and do a git log for each file. Is there a way to do it in one go and at least get the most recent commit hash for each such file.
I have tried this basic algorithm:
- Gather all files via git log --all --diff-filter=A --pretty=format: --name-only --date-order
- For each file, run git log -n1 --date-order --all --pretty=format:%H -- file
Step 1 takes a while (perhaps 30 seconds) but I can live with that since it's only done once.
Step 2 takes 3-4 seconds for each invocation of git log, which is much too slow when dealing with thousands of files.
I'm looking for some way to do this more efficiently, probably via plumbing.
Alternatively, if there's a way to speed up git log that could be a solution as well.