Git tips: Getting the first commit date of a file
Up a LevelUSAGE: 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 = "<missing>"; 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 = "<untracked>" if $reason =~ /^\s*$/s;
}
# Write out the results.
if (!$bare)
{
print "$filename: ";
}
# Print out the reason which will be <untracked>, <missing>, or a
# date.
print $reason, "\n";
}
Metadata
Categories:
Tags:
Footer
Below are various useful links within this site and to related sites (not all have been converted over to Gemini).
Contact
Biography
Bibliography
Support
Fedran (fedran.com)
Coding (https://mfgames.com)
The Moonfires (https://moonfire.us)
Tags
Colophon
License
Response: 20 (Success), text/gemini
| Original URL | gemini://d.moonfire.us/blog/2014/04/20/git-tips-getting-t... |
|---|---|
| Status Code | 20 (Success) |
| Content-Type | text/gemini; charset=utf-8; lang=en-US |