如何检查最新执行的“git pull”的日期和时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2993902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I check the date and time of the latest `git pull` that was executed?
提问by Chirag Patel
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.
如何检查最近git pull
执行的日期和时间?当出现问题时,我经常需要知道服务器上的代码何时更改。
采纳答案by Greg Hewgill
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.
该git show
命令显示最近提交的日期。这不是将提交拉到本地存储库的日期,但 Git 不会保留此类拉信息。
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:
您可以使用服务器上文件的 ctime(创建时间)找到上次拉取的时间。例如:
ls -lct
shows the ctime of each file, sorted with the most recent first.
显示每个文件的 ctime,以最近的排在最前面。
回答by smoove
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.
将为您提供该文件上次修改的 unix 时间戳。每次拉取或取回时,Git 都会写入 FETCH_HEAD 文件,即使没有可拉取的内容。
回答by Paul McMullin
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”,并得到了当时人类可读的打印输出:
> 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)
此外,您可以添加
when = !stat -c %y .git/FETCH_HEAD
到[alias]
~/.gitconfig 文件中的部分(通过在任何 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.]
[然后我想到要执行“man stat”,我发现还有许多其他 % 参数可用于“stat”程序。天啊。]
回答by araqnid
In a non-bare repository (and a bare repository doesn't make sense for git pull
), git logs all changes to branch tips and the current branch idea in "reflogs", in .git/logs
. You can view these using git log -g
.
在非裸存储库中(并且裸存储库对 没有意义git pull
),git 将所有更改记录到分支提示和当前分支想法的“reflogs”中,在.git/logs
. 您可以使用git log -g
.
However, although the log files do have timestamps, it doesn't appear that git log -g
will print it. However, if you take a look at .git/logs/HEAD
for example, you'll see that the format is quite simple to parse- it consists of what the ref (or HEAD) changed from, changed to, who changed it, when and an activity message.
然而,虽然日志文件确实有时间戳,但它似乎不会git log -g
打印出来。但是,如果您看一下.git/logs/HEAD
示例,您会发现该格式非常易于解析 - 它由 ref(或 HEAD)更改的内容、更改的内容、更改者、更改时间和活动消息组成。
回答by sachin_ur
git show -1 --stat
This git command shows the latest changes commits time and date with message
此 git 命令显示最新更改提交时间和日期以及消息
回答by widerin
Use python: python -c "import os;print os.stat('.git/FETCH_HEAD').st_mtime"
使用蟒蛇: python -c "import os;print os.stat('.git/FETCH_HEAD').st_mtime"
回答by RedEyed
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))"
回答by Josh Peak
Cross Platform (OSX/Linux) Bash Solution
跨平台 (OSX/Linux) Bash 解决方案
Heavily inspired by @smooves
answer: https://stackoverflow.com/a/9229377/622276and comments.
受到@smooves
答案的极大启发:https: //stackoverflow.com/a/9229377/622276和评论。
But I am maintaining my own bash prompt git integration
但我正在维护我自己的bash 提示 git 集成
With the source here: https://github.com/neozenith/dotfiles/blob/master/bash-scripts/function_parse_git_prompt.sh
来源:https: //github.com/neozenith/dotfiles/blob/master/bash-scripts/function_parse_git_prompt.sh
msys
version in Git Bash for Windows works identical to the linux version.
msys
Windows 版 Git Bash 中的版本与 linux 版本的工作方式相同。
I'm compiling the cross platform options into a case statement. So it will fork a fetch process on any git repo I navigate into that is older than fifteen minutes since last fetch so the rest of my prompt script knows if I have stuff to pull.
我正在将跨平台选项编译为 case 语句。因此,它会在我导航到的任何 git 存储库上分叉一个 fetch 过程,该过程自上次获取以来超过 15 分钟,因此我的提示脚本的其余部分知道我是否有东西要提取。
Git radarused to to this but it required saving a file with timestamp of when the last fetch was called. This writes no temporary files.
Git 雷达习惯于这样做,但它需要保存一个文件,其中包含上次调用时的时间戳。这不会写入临时文件。
git rev-parse --show-toplevel
just means if I'm anywhere in a git repo it will get the repo root so we can reference the .git
folder path.
git rev-parse --show-toplevel
只是意味着如果我在 git repo 中的任何位置,它将获得 repo 根,以便我们可以引用.git
文件夹路径。
# 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
回答by 1.61803
$ # for the latest pull even if there's 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 <[email protected]>)
Reflog message: pull: Fast-forward
Author: Ryan Schmidt <[email protected]>
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]
回答by Vineet Gupta
As suggested by user: https://stackoverflow.com/users/83646/smoove, you can find when git pull was last called on the repo by checking the modification timestamp of: .git/FETCH_HEAD as: git writes the .git/FETCH_HEAD file every time you pull or fetch, even if there was nothing to pull.
正如用户所建议的:https://stackoverflow.com/users/83646/smoove ,您可以通过检查以下修改时间戳来找到 git pull 上次在 repo 上调用的时间: .git/FETCH_HEAD as: git writes the .git/ FETCH_HEAD 文件每次拉或取时,即使没有什么可拉。
Example: {master} vinegupt@bhling69(/imsgit_local/work/vinegupt/ims_18.5a/ims_common)$ stat -c %y .git/FETCH_HEAD
示例:{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
2018-02-12 02:01:50.487160386 +0530