See “real” commit date in github (hour/day)

╄→尐↘猪︶ㄣ 提交于 2019-12-20 09:13:40

问题


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.

If it's not possible to see the actual date on github, is there a easier workaround than git clone?


回答1:


Hover your mouse over the 2 years ago and you'll get the timestamp.




回答2:


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.

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>




回答3:


you can just use this js bookmark:

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

It adds just the correct time: Like this: committed 21 hours ago -- 15. Feb. 2017, 15:49 MEZ




回答4:


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.

The following script seems to work on Github as of 2017-10-30:

(function() {
    var els = window.document.querySelectorAll("time-ago,relative-time");
    els.forEach(function(el) {
        el.innerHTML = el._date; // set original timestamp
        el.detachedCallback();   // stop auto-updates
    });
})();

You can make this a bookmarklet by prefixing the code with javascript: as in the other JS-based solution.

And if you want to make this a permanent fix, you can save this as a TamperMonkey/Greasemonkey script, as follows:

// ==UserScript==
// @name         Github: always show absolute times
// @match        https://github.com/*
// ==/UserScript==

(function() {
    var els = window.document.querySelectorAll("time-ago,relative-time");
    els.forEach(function(el) {
        el.innerHTML = el._date; // set original timestamp
        el.detachedCallback();   // stop auto-updates
    });
})();



回答5:


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.

// ==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. :)




回答6:


With gitlab 10 I used this to add the tooltip title to the element as standard text:

javascript:(function() { 
  var relativeTimeElements = window.document.querySelectorAll("time");
  relativeTimeElements.forEach(function(timeElement){
    timeElement.innerHTML = timeElement.innerHTML +" -- "+ timeElement.getAttribute('data-original-title');
  })
}());


来源:https://stackoverflow.com/questions/20500411/see-real-commit-date-in-github-hour-day

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!