Reputation: 1060
How do I, using git, list all files in a particular directory together with the owner/identity of those files at first commit?
Is getting slices of information like this across many files usually difficult?
Edit: Okay, git doesn't provide a direct way to do this, but it does store who commits various files, right? I need this list in a particular directory so I can get a sense of which files I'm 'responsible' for.
Upvotes: 10
Views: 6697
Reputation: 16185
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:
placeholders
under format:<string>
)Upvotes: 17
Reputation: 392893
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:
%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)
It will start out with the empty name, which is the root tree object.
Upvotes: 4
Reputation: 60255
To do this efficiently,
git log --raw --date-order --reverse --diff-filter=A --format=%H%x09%an \
| awk -F$'\t' '
/^[^:]/ {thisauthor=$2}
$1~/A$/ {print thisauthor "\t" $2}
'
with maybe a |sort -t$'\t' -k1,1
or something to make it a bit prettier
Upvotes: 1
Reputation: 1746
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 {} \;
Upvotes: 6
Reputation: 46334
Using git itself, this is not possible. Git does not keep track of the owner of the file.
Upvotes: 0