How to check the date and time of the last run of the `git pull` that was executed?

How to check the date and time of the last git pull that was executed? I often need to know when the code changed on the server, when something went wrong.

+74
git git-pull
Jun 07 '10 at 23:34
source share
11 answers

The git show command shows the date of the last commit. This is not the date that the commit was pulled to the local repository, but Git does not save this checkout information.

You can find the time of the last break using the ctime (creation time) of the files on the server. For example:

 ls -lct 

shows the ctime of each file sorted with the last first.

+18
Jun 07 '10 at 23:37
source share
 stat -c %Y .git/FETCH_HEAD 

Gives you the unix timestamp of the last modification of this file. Git writes the FETCH_HEAD file every time you pull or select, even if there was nothing to pull.

+116
Feb 10 '12 at 14:33
source share

On suspicion, I tried "stat -c% y.git / FETCH_HEAD" and got a user-friendly timestamp:

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

Alternatively, you can add when = !stat -c %y .git/FETCH_HEAD to the [alias] section in the ~ / .gitconfig file (the safest way to do this is by running the following command line in any git repository)

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

and then you can find this information with your new β€œcommand” at any time:

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

[Then it occurred to me to make a "man stat", and I found that there are several other parameters available for the "stat" program. YMMV.]

+25
Feb 24 '15 at 22:44
source share

In a non-bare repository (and an empty repository does not make sense for git pull ), git writes all changes to the branch hints and the current branch idea in "reflogs", in .git/logs . You can view them with git log -g .

However, although there are timestamps in the log files, it does not appear that git log -g will print it. However, if you look at .git/logs/HEAD , for example, you will see that the format is quite simple for analysis - it consists of how the ref (or HEAD) changed, which was changed, who changed it when and the message about the activity.

+8
Jun 07 2018-10-06T00:
source share

Use python: python -c "import os;print os.stat('.git/FETCH_HEAD').st_mtime"

+1
Mar 22 '15 at 2:42
source share
 python -c "import os, datetime ;print datetime.datetime.fromtimestamp(os.stat('.git/FETCH_HEAD').st_mtime)" 

or

 python3 -c "import os, datetime ;print(datetime.datetime.fromtimestamp(os.stat('.git/FETCH_HEAD').st_mtime))" 
+1
Oct 10 '18 at 6:25
source share
 $ # for the latest pull even if there nothing new $ stat -c %y .git/FETCH_HEAD 2017-12-15 11:24:25.000000000 +0100 $ $ # for records of updated references $ git reflog --date=iso db2bba84 (HEAD -> master, origin/master, origin/HEAD) HEAD@{2017-12-14 11:28:39 +0100}: pull: Fast-forward 37fe73ad HEAD@{2017-12-03 17:09:32 +0100}: pull: Fast-forward c4107fcd HEAD@{2017-11-27 18:53:40 +0100}: clone: from https://github.com/macports/macports-base $ $ # for a more detailed view of the latter $ git log -g commit db2bba84d5e8cd82ec94a19129deb91ef62287bb (HEAD -> master, origin/master, origin/HEAD) Reflog: HEAD@{0} (me <me@machine.local>) Reflog message: pull: Fast-forward Author: Ryan Schmidt <ryandesign@macports.org> Date: Wed Dec 13 10:23:47 2017 -0600 portutil.tcl: Fix renames that supply the -force option Treat $options as a list not as a string. See: https://trac.macports.org/ticket/55492 [snip] 
0
Dec 15 '17 at 4:43 on
source share
 git show -1 --stat 

This git command shows the latest changes; captures the time and date with a message

0
Oct 16 '18 at 11:51
source share

For the current branch, you can get the dates of all the git pull commands you executed by doing the following:

 $ for i in $(cat .git/logs/refs/heads/<YOUR_BRANCH_NAME_HERE> | grep pull | awk '{print $5}');do date -d@$i; done 

Note. The awk argument may vary depending on the version of git. This awk arg works for git version 1.8.3.1 .

0
Jan 18 '19 at 5:42
source share

Cross-platform (OSX / Linux) Bash solution

Inspired by @smooves answer: https://stackoverflow.com/a/166268/ and the comments.

But I support native integration with gash in bash

With source here: https://github.com/neozenith/dotfiles/blob/master/bash-scripts/function_parse_git_prompt.sh

The msys version on Git Bash for Windows works the same as the linux version.

I collect cross-platform options in case management. That way, it will handle the extraction process for any git repo that I go to and that is older than fifteen minutes from the last fetch, so the rest of my invitation script knows if I have anything to extract.

Git radar was used to it, but for this it was necessary to save the file with the timestamp when the last fetch was called. This writes no temporary files.

git rev-parse --show-toplevel just means that if I am somewhere in the git repo, it will get the repo root so that we can reference the path to the .git folder.

 # No repo == no more work local REPO_ROOT='git rev-parse --show-toplevel 2> /dev/null' if [[ -n $REPO_ROOT && -e "$REPO_ROOT/.git/FETCH_HEAD" ]]; then case $OSTYPE in darwin*) local LAST_FETCH="$(stat -f '%m' $REPO_ROOT/.git/FETCH_HEAD)" local FETCH_THRESHOLD="$(date -v-15m +%s)" ;; *) local LAST_FETCH="$(stat -c %Y $REPO_ROOT/.git/FETCH_HEAD)" local FETCH_THRESHOLD="$(date -d'15 minutes ago' +%s)" ;; esac # Fork fetch process in background if [[ $LAST_FETCH -lt $FETCH_THRESHOLD ]]; then git fetch --all --quiet --prune 2> /dev/null & fi fi 
0
Jan 19 '19 at 5:02
source share

According to the user's suggestion: https://stackoverflow.com/users/83646/smoove , you can find out when git pull was last called in the repo by checking the change timestamp: .git / FETCH_HEAD, since: git writes .git / FETCH_HEAD file every time you extract or extract, even if there was nothing to extract.

Example: {master} vinegupt @ bhling69 (/imsgit_local/work/vinegupt/ims_18.5a/ims_common) $ stat -c% y.git / FETCH_HEAD

2018-02-12 02: 01: 50.487160386 +0530

-one
Feb 13 '18 at 4:49
source share



All Articles