git 查看 github 中的“真实”提交日期(小时/天)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20500411/
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
See "real" commit date in github (hour/day)
提问by goncalopp
Is there a way to see the date of a commit in github, with day/hour precision? Older commits appear in a "human readable" format, such as "2 years ago" instead of showing the actual date.
有没有办法以日/小时的精度查看 github 中提交的日期?较旧的提交以“人类可读”的格式出现,例如“2 年前”,而不是显示实际日期。
If it's not possible to see the actual date on github, is there a easier workaround than git clone
?
如果无法在 github 上看到实际日期,是否有比 更简单的解决方法git clone
?
回答by Matt S.
Hover your mouse over the 2 years ago
and you'll get the timestamp.
将鼠标悬停在 上2 years ago
,您将获得时间戳。
回答by Walter Roman
The real date does not appear for me upon hovering "2 years ago", despite the text being wrapped by a <time>
element with an iso value under its datetime
attribute.
尽管文本被<time>
其datetime
属性下具有 iso 值的元素包裹,但在悬停“2 年前”时不会出现实际日期。
If all else fails, like it did for me, try inspecting the text.
如果所有其他方法都失败了,就像对我一样,请尝试检查文本。
Sample element:
示例元素:
<time datetime="2015-01-22T20:48:13Z" is="relative-time" title="Jan 22, 2015, 2:48 PM CST">7 days ago</time>
<time datetime="2015-01-22T20:48:13Z" is="relative-time" title="Jan 22, 2015, 2:48 PM CST">7 days ago</time>
回答by Philipp Grulich
you can just use this js bookmark:
你可以只使用这个js书签:
javascript:(function() {
var relativeTimeElements = window.document.querySelectorAll("relative time");
relativeTimeElements.forEach(function(timeElement){
timeElement.innerHTML = timeElement.innerHTML +" -- "+ timeElement.title;
})
}()
)
https://gist.github.com/PhilippGrulich/7051832b344d4cbd30fbfd68524baa38
https://gist.github.com/PhilippGrulich/7051832b344d4cbd30fbfd68524baa38
It adds just the correct time: Like this: committed 21 hours ago -- 15. Feb. 2017, 15:49 MEZ
它添加了正确的时间:像这样:21 小时前提交 - 2017 年 2 月 15 日,MEZ 15:49
回答by Mr. T
I tried @odony's TamperMonkey/Greasemonkey script on Chrome but couldn't get it to work. detachCallback()
wasn't recognized. So instead of detaching any callbacks, I simply replaced the <relative-time>
node.
我在 Chrome 上尝试了 @odony 的 TamperMonkey/Greasemonkey 脚本,但无法让它工作。detachCallback()
不被认可。因此,我没有分离任何回调,而是简单地替换了<relative-time>
节点。
// ==UserScript==
// @name Github: always show absolute times
// @match https://github.com/*
// ==/UserScript==
(function() {
document.querySelectorAll("relative-time").forEach(function(el) {
var parent = el.parentNode;
var timestamp = el.title;
var span = document.createElement("span");
span.innerHTML = timestamp;
parent.removeChild(el);
parent.appendChild(span);
});
})();
Sorry I haven't tested this with other browser, but since this is basic javascript, it should just work. :)
抱歉,我没有用其他浏览器测试过这个,但由于这是基本的 javascript,它应该可以正常工作。:)
回答by odony
If you're looking for a way to display the date/time permanently without hovering (e.g. for screenshots), the above Javascript-based solutions do not match the latest Github HTML (see comments). And they did not take into account the fact that the timestamps are auto-updated based on a timer ("X minutes ago"has to change every minute), so they will periodically reappear.
如果您正在寻找一种无需悬停即可永久显示日期/时间的方法(例如用于屏幕截图),上述基于 Javascript 的解决方案与最新的 Github HTML 不匹配(请参阅评论)。而且他们没有考虑到时间戳是根据计时器自动更新的事实(“X 分钟前”必须每分钟更改一次),因此它们会定期重新出现。
The following script seems to work on Github as of 2020-01-27:
截至 2020 年 1 月 27 日,以下脚本似乎可在 Github 上运行:
(function() {
var els = window.document.querySelectorAll("time-ago,relative-time");
els.forEach(function(el) {
el.innerHTML = "on " + el.getFormattedTitle(); // original timestamp
el.disconnectedCallback(); // stop auto-updates
});
})();
You can make this a bookmarkletby prefixing the code with javascript:
as in the other JS-based solution.
您可以通过在其他基于 JS 的解决方案中为代码添加前缀来使其成为书签javascript:
。
And if you want to make this a permanentfix, you can save this as a TamperMonkey/Greasemonkey script, as follows:
如果您想永久修复此问题,您可以将其另存为 TamperMonkey/Greasemonkey 脚本,如下所示:
// ==UserScript==
// @name Github: always show absolute times
// @match https://github.com/*
// ==/UserScript==
(function() {
setTimeout(function() {
var els = window.document.querySelectorAll("time-ago,relative-time");
els.forEach(function(el) {
el.innerHTML += ' <span class="text-small">(' + el.title + ')</span>'; // set original timestamp
el.disconnectedCallback(); // stop auto-updates
});
}, 100); // YMMV, experiment with the timeout
})();
That's not very pretty but it seems to do the job.
这不是很漂亮,但似乎可以完成这项工作。
回答by Xeno
With gitlab 10 I used this to add the tooltip title to the element as standard text:
在 gitlab 10 中,我使用它来将工具提示标题作为标准文本添加到元素中:
javascript:(function() {
var relativeTimeElements = window.document.querySelectorAll("time");
relativeTimeElements.forEach(function(timeElement){
timeElement.innerHTML = timeElement.innerHTML +" -- "+ timeElement.getAttribute('data-original-title');
})
}());