Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the last commit date for a bunch of files in Git?

Tags:

git

What's the simplest one-liner to get the last commit date for a bunch of files in a Git repository (i.e., for each file, the date of the last commit that changed that file)?

The context for this is that I'm using other Bash commands to find a long list of files matching some criteria, and I'd like to just pipe this list into a Git command to get the last commit date for each file.

like image 953
jonderry Avatar asked Dec 23 '11 01:12

jonderry


People also ask

How do I see file commit history?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

How do I get the last commit hash?

# open the git config editor $ git config --global --edit # in the alias section, add ... [alias] lastcommit = rev-parse HEAD ... From here on, use git lastcommit to show the last commit's hash.

How do I get the latest commit of a branch?

If you need to get latest commit on a branch through the REST api, try the "/commits" call with the "until" parameter set to the branch you are interested in, and limit=1 to get the single tip commit from the branch.


1 Answers

The following command will be helpful:

git log -1 --format=%cd filename.txt 

This will print the latest change date for one file. The -1 shows one log entry (the most recent), and --format=%cd shows the commit date. See the documentation for git-log for a full description of the options.

You should be able to easily extend this for a group of files.

like image 183
Greg Hewgill Avatar answered Sep 28 '22 15:09

Greg Hewgill