# Git tips: Getting the first commit date of a file => .. Up a Level # USAGE: git-first-commit-date [–bare|-b] file… ## ## Setup ## ## Directives use strict; use warnings; ## Modules use Getopt::Long; ## ## Options ## ## –bare means don't put the filename in the line. Otherwise it will ## –put the filename, followed by a colon and a space. my $bare = 0; &GetOptions( “b|bare!” => $bare, ); ## ## Go through the input files. ## while (@ARGV) { # Pull out the filename. my $filename = shift @ARGV; my $reason = ""; my $valid = 0; ``` if (-f $filename) { # Get the date for the file. We tell Git to only give us the # ISO date (https://xkcd.com/1179/) for the files using # --pretty=format:%ad --date=short. We use --follow to handle # renames. Finally, we get the last one (the earliest # date). --reverse didn't seem to work, so we skip that. $reason = `git log --follow --pretty=format:%ad --date=short "$filename" | tail -n 1`; chomp $reason; # If we have a date, use it. Otherwise say it is untracked. $reason = "" if $reason =~ /^\s*$/s; } # Write out the results. if (!$bare) { print "$filename: "; } # Print out the reason which will be , , or a # date. print $reason, "\n"; ``` } # Metadata Categories: => /categories/programming/ Programming Tags: => /tags/perl/ Perl # Footer Below are various useful links within this site and to related sites (not all have been converted over to Gemini). => /now/ Now => /contact/ Contact => /bio/ Biography => /bibliography/ Bibliography => /support/ Support => /fiction/ Fiction => //fedran.com/ Fedran => https://mfgames.com/ Coding => https://moonfire.us/ The Moonfires => /categories/ Categories => /tags/ Tags => /privacy/ Privacy => /colophon/ Colophon => /license/ License => https://lists.typewriter.press/subscription?f=RDQ6f3AFHXnX2o763d5TgUmaYP7N763gR6FjZyGUUFWhyRkpgZF9I35ySICDBEdFFtgG Mailing List => https://d.moonfire.us/blog/2014/04/20/git-tips-getting-the-first-commit-date-of-a-file/