如何让git diff只显示提交消息

时间:2015-11-10 22:59:51

标签: git

如何使用git diff仅显示提交消息?我只想要提交的消息而不是文件的名称。我想在git中获取更改日志。

4 个答案:

答案 0 :(得分:3)

function MyWebsocket(server, port) {
    this.timeout = 2000;
    this.clearTimer = -1;
    this.data = {};
    this.socket = {};
    this.server = server;
    this.port = port;
    this.regMessage = "";
    this.setOnMessage = "";
    this.action = "";
};

MyWebsocket.getSocket = function (ws) {
    if(this.map == NaN) { this.map = {} };
    return this.map[ws]
};
MyWebsocket.setSocket = function (object) {
    this.map[object.socket] = object;
    return object;
};

MyWebsocket.prototype.setRegMessage = function (message) {
    this.regMessage = message;
};


MyWebsocket.prototype.getData = function () {
    return this.data;
}

MyWebsocket.prototype.getSocketState = function () {
    console.log("get state; port: " + this.port);
    return (this.socket != null) ? this.socket.readyState : 0;
};

MyWebsocket.prototype.onOpen = function () {
    console.log("open; port: "  + this.port);
    clearInterval(this.clearTimer);
    this.send();
};

MyWebsocket.prototype.send = function () {
    this.socket.send(this.regMessage);
};

MyWebsocket.prototype.onError = function (event) {
    var my = MyWebsocket.getSocket(this)
    console.log("error; port: " + my.port);
    my.errorMessage(event);
    clearInterval(my.clearTimer);
    this.onclose = function () {};
    my.clearTimer = setInterval(" this.connect()", my.timeout);
};

MyWebsocket.prototype.onClose = function (event) {
    var my = MyWebsocket.getSocket(this)
    console.log("close; port: " + my.port);
    my.errorMessage(event);
    clearInterval(my.clearTimer);
    my.clearTimer = setInterval(" this.connect()", my.timeout);
};

MyWebsocket.prototype.onMessage = function (e) {
    var data = JSON.parse(e.data);
    switch (data.action) {
    case "Action1": { getAction1(data); break;}
    case "Action2": { getAction2(data); break;}
}
};

MyWebsocket.prototype.connect = function () {
    if ("WebSocket" in window) {
        if (this.getSocketState() === 1) {
            this.socket.onopen = this.onOpen;
            clearInterval(this.clearTimer);
            console.log(this.getSocketState());
        }
        else {
            try {
                var host = "ws://" + this.server + ":" + this.port;
                this.socket = new WebSocket(host);
                MyWebsocket.setSocket(this)
                console.log(this.socket);
                this.socket.onopen = this.onOpen;
                this.socket.onmessage = this.onMessage
                this.socket.onerror = this.onError;
                this.socket.onclose = this.onClose;
            }
            catch (exeption) {
                console.log(exeption);
            }
        }
    }
};
MyWebsocket.prototype.disconnect = function () {
    console.log("disconnect; port: " + this.port);   
       this.socket.onclose = function (event) {};
       this.socket.close(1000);
};

它将在单行上打印出最后n(10)次提交。只是提交消息。

您还可以将其与其他日志参数组合使用,如:

git log --oneline -n 10

答案 1 :(得分:2)

git log --pretty=%B

将显示最后的提交消息。

如果您想限制数字N显示的提交消息数,可以通过另外提供 - N 来实现这一点。

git log -3 --pretty=%B

表示最后3条提交消息。

答案 2 :(得分:1)

除了Simon Clewer's答案:

git log master..dev --no-merges --pretty='format:%cs %s'

仅打印master和dev之间的提交主题(没有合并提交)。像这样:

2020-12-31 Hot fix
2020-12-30 Change some stuff
2020-12-29 Add the feature

在本地和远程分支之间切换:

git log HEAD..origin --no-merges --pretty='format:%cs %s'

另请参阅Good ways to manage a changelog using git?

答案 3 :(得分:0)

您可以尝试使用git log,

git log commitA...commitB

三点符号“ ...”仅为您提供所有可从commitA或commitB而不是从两者访问的提交的提交消息,即commitA和commitB之间的区别。

您可以轻松地将提交信息简化为

git log --pretty=%B commitA...commitB

一些例子

# show log of all commits in either development branch or master branch since they diverged.
git log --pretty=%B development...master
# show log of all commits made to either commit b8c9577  or commit 92b15da but not to both.
git log --pretty=%B b8c9577...92b15da
# show log for all commits unique to either local branch master or local version of the origin's master branch. 
git co master
git log --pretty=%B master...origin/master
# show log for all commits unique to either local HEAD or local version of the origin's master branch. 
git co master
# hack, hack
git log --pretty=%B HEAD...origin/master