Skip to content

shaojintian/auto-commit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Principle

命令 作用
git --amend 简单地来说,可以理解成对最后一次提交做修正
git --no-edit
git --date 见下文

有时需要修改上次git commit的时间,比如之前将代码提交到本地库中,现在想将这次提交推送到远程仓库,但是这次提交的时间显示还是昨天的时间,下面提供一个办法用于修改上次提交的时间: 使用:

git commit --amend --date="commit_time"

commit_time的格式比较难记,不过有个小技巧,我们可以先在命令行输入:

date -R
Sat, 24 Dec 2016 18:12:09 +0800

这个命令的输出格式与git commit –amend –date命令要填写的日期格式相同,自己再稍加修改一下即可。 如果我们只是想将上次git commit的时间 改为当前时间,可以使用以下两个命令:

git commit --amend --date="$(date -R)"
#
git commit --amend --date=`date -R`

对于如何修改任意git commit的时间,也简单,按照date -R命令的输出格式自己构造commit_time即可。

git commit --amend --date="Sun, 25 Dec 2016 19:42:09 +0800"
git commit --amend --no-edit --date="Sun, 25 Dec 2016 19:42:09 +0800"
git push origin master --force

date参数

Change history: amending and editing dates There might be certain situations where you want to alter the timestamps git assigns to commits. There are a couple of ways that you can do this.

Use --date

The --date option allows you to specify the author date that git attaches to the commit. Here we can’t use approxidate unfortunately, only fixed dates will work (YYYY.MM.DD, MM/DD/YYYY, DD.MM.YYYY, RFC 2822 and ISO 8601 are all valid).

git commit --date="Wed Feb 16 14:00 2037 +0100"

We can also use amend to change the timestamp of a previous commit:

git commit --amend --date="Wed Feb 16 14:00 2037 +0100"

Unfortunately --date will only change the GIT_AUTHOR_DATE, not GIT_COMMITTER_DATE. If this is a problem, you may need to…

Manually set GIT_AUTHOR_DATE and GIT_COMMITTER_DATE

时间格式

  • rfc2822: Mon, 3 Jul 2006 17:18:43 +0200
  • iso8601: 2006-07-03 17:18:43 +0200
  • local: Mon Jul 3 15:18:43 2006
  • short: 2006-07-03 (not in 1.9.1, works in 2.3.0)
  • relative: see commit 34dc6e7:
5.seconds.ago, 
2.years.3.months.ago, 
'6am yesterday'
  • raw: see commit 7dff9b3 (git 1.6.2, March 2009)

  • internal raw git format - seconds since epoch plus timezone (put another way: 'date +"%s %z"' format)

  • default: Mon Jul 3 17:18:43 2006 +0200

全局AJAX监听

改写XMLHttpRequest原型链上面的open方法,监听全局的ajax请求发送

function modifyResponse(response) {
    if (this.readyState === 4) {
        console.log(response.target.response);
    }
}
XMLHttpRequest.prototype.open = openBypass(XMLHttpRequest.prototype.open);
function openBypass(original_function) {
    return function (method, url, async) {
        // 保存请求相关参数
        this.requestMethod = method;
        this.requestURL = url;
        this.addEventListener("readystatechange", modifyResponse);
        return original_function.apply(this, arguments);
    };
}
var open = window.XMLHttpRequest.prototype.open,
    send = window.XMLHttpRequest.prototype.send,
    ReadyStateChange;

function openReplacement(method, url, async, user, password) {
    open.apply(this, arguments);
}

function sendReplacement(data) {
    var ajaxReadyStateChange,
        ajaxLoad;
    console.warn('Sending HTTP request data : ', data);
    // onreadystatechange replacement
    if (this.onreadystatechange) {
        ReadyStateChange = this.onreadystatechange;
    }
    this.onreadystatechange = function () {
        console.warn('HTTP request ready state changed : ' + this.readyState);
        ajaxReadyStateChange = new CustomEvent('ajaxReadyStateChange', { detail: this });
        window.dispatchEvent(ajaxReadyStateChange);
        if (ReadyStateChange) {
            ReadyStateChange.apply(this, arguments);
        }
        // onload
        if (this.readyState === 4) {
            ajaxLoad = new CustomEvent('ajaxLoad', { detail: this });
            dispatchEvent(ajaxLoad);
        }
    };
    send.apply(this, arguments);
}
window.XMLHttpRequest.prototype.open = openReplacement;
window.XMLHttpRequest.prototype.send = sendReplacement;

About

🕧Change GitHub History

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published