如何检查最近执行的“git pull”的日期和时间?
如何检查最近执行的 git pull 的日期和时间?当出现问题时,我经常需要知道服务器上的代码何时发生更改。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
在非裸存储库中(裸存储库对于 git pull 没有意义),git 会在
的“reflogs”中记录对分支提示和当前分支想法的所有更改。 git/logs
.您可以使用 git log -g 来查看这些内容。然而,尽管日志文件确实有时间戳,但 git log -g 似乎不会打印它。但是,如果您查看
.git/logs/HEAD
例如,您会发现该格式非常易于解析 - 它由 ref (或 HEAD)更改的内容组成,更改为、谁更改、何时更改以及活动消息。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 usinggit 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.跨平台 (OSX/Linux) Bash 解决方案
深受
@smooves
答案的启发:https://stackoverflow.com /a/9229377/622276 和评论。但我正在维护我自己的 bash 提示 git 集成
源代码如下:
https://github.com/neozenith/dotfiles/blob/ Git Bash for Windows 中的master/bash-scripts/function_parse_git_prompt.sh
msys
版本与 Linux 版本的工作方式相同。我正在将跨平台选项编译成案例陈述。因此,它将在我导航到的任何 git 存储库上分叉一个提取过程,该过程自上次提取以来已超过十五分钟,这样我的提示脚本的其余部分就知道我是否有东西要提取。
Git Radar 用于此操作,但需要保存一个文件,其中包含上次获取的时间戳叫。这不会写入临时文件。
git rev-parse --show-toplevel 只是意味着如果我位于 git 存储库中的任何位置,它将获取存储库根目录,以便我们可以引用 .git 文件夹路径。
Cross Platform (OSX/Linux) Bash Solution
Heavily inspired by
@smooves
answer: https://stackoverflow.com/a/9229377/622276 and comments.But I am maintaining my own bash prompt git integration
With the source here:
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.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.
Git radar used to to this but it required saving a file with timestamp of when the last fetch was called. This writes no temporary files.
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.使用Python:
Use Python:
或者
or
根据用户的建议:https://stackoverflow.com/users/83646/smoove,您可以找到 git pull 的时间最后通过检查 .git/FETCH_HEAD 的修改时间戳来调用存储库:每次拉取或提取时,git 都会写入 .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
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.
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
这是一个小的 git 包装器。使用名称
git
和权限chmod a+x git
安装它。然后将last_successful_fetch
添加到.git/info/exclude
中。当您想查看结果时,请使用
stat last_successful_fetch
。Here's a small git wrapper. Install it with the name
git
and with rightschmod a+x git
. Then addlast_successful_fetch
to.git/info/exclude
.When you want to see the result, use
stat last_successful_fetch
.就我而言,我必须返回以获取倒数第二个拉取(previous-1),因此使用了此 reflog 命令,请注意,reflog 默认在 90 天后过期。希望这对某人有帮助。
然后你可以签出该哈希并创建一个分支。 (以下命令中的分离头)
In my case I had to go back to get the second to last pull (previous-1), so used this reflog command, note that reflogs expire in 90 days by default. Hope this will be helpful to someone.
then you can checkout that hash and create a branch. (detached head in below command)
为什么不使用最简单的,
只要它不到 1 岁就可以工作
并且您只需要日期(时间 hh:mm 仅在不到 1 天的情况下显示)
应该适用于任何操作系统(系统)、任何带有任何 shell 的 FS(文件系统)
除非有人在 .git 文件夹中搞砸了
顺便说一句, ls -c 可能会使用状态更改日期时间来排序和/或打印
不是创建日期时间(在某些条件下可能匹配)。
男人ls
-c 使用上次更改文件状态以进行排序或打印的时间。
why not use the simplest
it works as long it's less than 1 year old
and you only need the date (time hh:mm is only displayed if less than 1 day old)
should work on any OS (system), any FS (FileSystem) with any shell
except if someone messes up inside the .git folder
By the way, ls -c may use status change datetime to sort and/or print
not creation datetime (it may matches in some conditions).
man ls
-c Use time when file status was last changed for sorting or printing.
将为您提供该文件最后一次修改的 unix 时间戳。
每次拉取或获取时,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.
凭直觉,我尝试了“stat -c %y .git/FETCH_HEAD”,并得到了当时人类可读的打印输出:
此外,您可以添加
when = !stat -c %y .git/FETCH_HEAD
到 ~/.gitconfig 文件中的[alias]
部分(通过运行以下命令自动执行此操作是最安全的任何 git 存储库中的命令行),然后您可以随时使用新的“命令”找到此信息:
[然后我想到要做“man stat”,我发现还有一堆其他 % 参数可用于“stat”程序。 YMMV。]
On a hunch, I tried "stat -c %y .git/FETCH_HEAD", and got a human-readable printout of the time:
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)and then you are able to find this info with your new "command", anytime:
[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.]
git show
命令显示最近提交的日期。这不是提交被拉取到本地存储库的日期,但 Git 不会保留此类拉取信息。您也许可以使用服务器上文件的 ctime(创建时间)找到上次拉取的时间。例如:
显示每个文件的 ctime,以最新的在前排序。
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:
shows the ctime of each file, sorted with the most recent first.