Reputation: 4558
I want to get a table or csv (and eventually visualize it) about every file in git repository and every date when files were changed.
Expected output:
The number is how many commits contain that file per day
Date1 file1 12
Date1 file2 4
Date2 file1 6
Probably I should go and iterate trough all the commits and get somehow the modified files from every commit. Would you help me please?
RESEARCH
For iterating trough commits I found this => Git: want to iterate through all commits on branch, and list files in each commit
Getting the commit info
git diff --name-only SHA1 SHA2
How to get the date of a commit?
git show $commit
(Here I need all the files which were modified and the commit date)
Figure out how to output this as a csv file.
Probably this is out of the scope here because the question is for Git. If someone wants to help is welcome.
PROGRESS:
for commit in $(git rev-list master)
do
# Get the author date
git log -1 ${commit} --pretty="%ad" --date=short
# get the files changes
git diff --name-only ${commit}^!
done | sort | uniq -c | sort -rn
Upvotes: 0
Views: 491
Reputation: 14883
Dates in Git usually don't mean what people think or want them to be.
Each commit has 2 dates associated it - the author date, and the committer date. Both of those are taken from the computer clock of whomever made the commit, and they can both be overridden via the command line. As such, they are not particularly reliable indicators of anything.
The bigger issue though is that merely tells you the information that was recorded in the original repository in which the commit was made or authored. When you are talking about a DVCS that has implications. If I committed something last summer, and then today pushed it to a shared server you would see last summers date on the commit. Is that what you want? (I'm guessing "no") If not, then you need to have something set up via a receive hook on the server to log dates for you.
If you want to continue with your original path then I would suggest you do something along these lines. Start with this. It will dump "date file". You can then put that to anything you want to collate the results (awk, perl, python, etc.)
for commit in $(git rev-list master)
do
# Get the author date
commitDate=$(git log -1 ${commit} --pretty="%ad" --date=short)
# get the files changes
git diff --name-only ${commit}^! | xargs -n1 -I {} echo ${commitDate} {}
done
Upvotes: 4