How do I check the date and time of the latest `git pull` that was executed?

How do I check the date and time of the latest git pull that was executed? I frequently need to know when the code changed on a server when something goes wrong.


Solution 1:

stat -c %Y .git/FETCH_HEAD

Will give you a unix timestamp of the last modification of that file. Git writes the FETCH_HEAD file every time you pull or fetch, even if there was nothing to pull.

Solution 2:

On a hunch, I tried "stat -c %y .git/FETCH_HEAD", and got a human-readable printout of the time:

> stat -c %y .git/FETCH_HEAD
2015-02-24 17:42:08.072094410 -0500

Furthermore, you can add when = !stat -c %y .git/FETCH_HEAD to the [alias] section in your ~/.gitconfig file (it's safest to do this automatically by running the following command line in any git repo)

git config --global alias.when '!stat -c %y .git/FETCH_HEAD'

and then you are able to find this info with your new "command", anytime:

> git when
2015-02-23 15:07:53.086254218 -0500

[Then it occurred to me to do "man stat", and I found that there are a bunch of other % parameters available for the 'stat' program. YMMV.]

Solution 3:

The git show command shows the date of the most recent commit. This isn't the date at which the commit was pulled to the local repository, but Git doesn't keep such pull information.

You may be able to find the time of the last pull using the ctime (creation time) of the files on the server. For example:

ls -lct

shows the ctime of each file, sorted with the most recent first.