git: list all files with owner/identity at first commit (or rather, the first user to commit the file)
Give this a try:
$ cd thatdirectory
$ git ls-files |
while read fname; do
echo "`git log --reverse --format="%cn" "$fname" | head -1` first added $fname"
done
The "first added" can be misleading in case of renames.
Refs:
- https://git-scm.com/docs/git-ls-files
- https://git-scm.com/docs/git-log#_pretty_formats (see
placeholders
underformat:<string>
)
A very straightforward approach would be
git rev-list --objects --all |
cut -d' ' -f2- |
sort -u |
while read name; do
git --work-tree=. log --reverse --format="%cn%x09$name" -- "$name" | head -n1
done
Caveats:
- This shows the first author name (
%an
) of each path that exists in the object database (not just in (any) current revision). You may also want the committer name (%cn
), though be aware that if person B rebased a commit from person A that created the file, B will be the committer and A will be the author. The --all flag signifies that you want all objects on all branches. To limit scope, replace it by the name of the branch/tag or just by
HEAD
n2 performance (doesn't scale well for very large repo's)
- improper output if the pathname contains formatting sequences (e.g. %H etc.)
It will start out with the empty name, which is the root tree object.
I happened to run into a similar situation. The accepted answer is working, but why don't you guys use find
with working copy?
find . -type f -exec git log --reverse --format="{} %cn" -1 {} \;