在push之前有时候会不放心是不是忘记加某些文件,或者是不是多删了个什么东西,这时候希望能够看看上次commit都做了些什么。

一开始想到的是用Git diff,但是git diff用于当前修改尚未commit的时候较为方便,一旦commit后,需要指定上次节点的名称(一个hash值),不方便。这种时候用git log更合适,因为commit的内容会以log来记录。

下面记录几个常用的情境以及对应的命令。

仅仅想看最近谁有提交,以及提交的描述

对应命令 git log

显示Sample

commit 6305aa81a265f9316b606d3564521c43f0d6c9a3 
Author: XXX 
Date:   Thu Nov 3 11:38:15 2011 +0800

fill author information in the head of files and format some code

commit 8e8a4a96e134dab8f045937efee35bd710006946 
Author: XXX 
Date:   Thu Nov 3 04:05:34 2011 +0800

user management is mostly complete

details: 
    add support for account disable/enable 
    rewrite most related views to suit the above need 
    provide two decorators for access control (see README) 
    fixed many errors in Milestone 1

commit 2870cd564371d8ad043d0da426a5770d36412421 
Author: XXX 
Date:   Mon Oct 17 20:19:04 2011 -0400

fix the bug of get_ori_url_from_shorturl().

commit b6cdd881a19ecaff838d5825c3a6b7058fdd498a 
Author: XXX 
Date:   Mon Oct 17 20:17:37 2011 -0400

fix the bug of get_article_from_short_url.

仅仅想看最后一次的提交

对应命令参数 -n 1

显示Sample

commit 6305aa81a265f9316b606d3564521c43f0d6c9a3 
Author: XXX 
Date: Thu Nov 3 11:38:15 2011 +0800

fill author information in the head of files and format some code

想看到最近一次提交所有更改过的文件

对应命令 git log -n 1 --stat

显示Sample

commit 6305aa81a265f9316b606d3564521c43f0d6c9a3 
Author: XXX 
Date:   Thu Nov 3 11:38:15 2011 +0800

fill author information in the head of files and format some code

Site/accounts/decorators.py                        |    2 +- 
Site/accounts/forms.py                             |    1 + 
Site/accounts/models.py                            |    1 + 
Site/accounts/readme                               |    3 ++- 
Site/accounts/templates/account_activate.html      |    1 + 
Site/accounts/templates/account_disabled.html      |    1 + 

28 files changed, 37 insertions(+), 8 deletions(-)

想看到最近一次提交所有更改的细节

对应命令 git log -n 1 -p

显示Sample

commit 6305aa81a265f9316b606d3564521c43f0d6c9a3 
Author: XXX 
Date:   Thu Nov 3 11:38:15 2011 +0800

fill author information in the head of files and format some code

diff --git a/Site/accounts/decorators.py b/Site/accounts/decorators.py 
index 22522bc..a6bb440 100755 
--- a/Site/accounts/decorators.py 
+++ b/Site/accounts/decorators.py 
@@ -1,9 +1,9 @@ 
#!/usr/bin/env Python 
# -*- coding: utf-8 -*- 
+# author: Rex Nov. 3, 2011 
from functools import wraps 
from django.core.urlresolvers import reverse 
from django.http import HttpResponseRedirect 
-from django.utils.decorators import available_attrs 
from Site.accounts.models import UserProfile

def login_required(view_func): 
diff --git a/Site/accounts/forms.py b/Site/accounts/forms.py 
index 016710b..778d92a 100755 
--- a/Site/accounts/forms.py 
+++ b/Site/accounts/forms.py 
@@ -1,5 +1,6 @@ 
#!/usr/bin/env python 
# -*- coding: utf-8 -*- 
+# author: Rex Nov. 3, 201

有了这几条命令,基本上对于想看最近更改的情境就可以应付过去了。最后一条并不很常用,如果有visual的工具可能更直观些。

 
 

git使用点滴:如何查看commit的内容的更多相关文章

  1. Git 撤销所有未提交(Commit)的内容

    撸了好多代码,但是突然设计改了(~~o(>_<)o ~~):或者引入个第三方库,后来又发现用不着,想删掉,但文件太多了(比如几百个):那,怎么办呢,都不想了...Git 比人聪明,所以能很 ...

  2. git修改最后一次commit的内容

    提交修改 $ git add test.txt $ git commit -m "提交test.txt文件" 修改注释说明 如果需要修改commit的注释说明,则执行以下命令: $ ...

  3. 巧用 git rebase 合并多个 commit。

    一.为什么需要合并多个 commit 呢?   有时候,我们开发一个功能. 修修补补 commit 了很多次,过多的 commit 会显得很复杂. 不够直观,不能比较清晰查看那些 commit 是对应 ...

  4. git 查看commit提交的内容

    在使用git的过程中,我们经常需要查看某次commit修改了哪些内容,与之相关的命令就是: git log git show 首先,需要通过git log打印所有commit hashID,之后的gi ...

  5. Git以及github的使用方法(三),git status查看工作区的状态,git diff查看具体修改内容

    我们已经成功地添加并提交了一个readme.txt文件,现在,是时候继续工作了,于是,我们继续修改readme.txt文件,改成如下内容: Git is a distributed version c ...

  6. 【Git】Git如何合并某一次commit的内容到指定分支

    一.我是在什么场景下会用到该Git操作 当某同事,将开发分支dev2合并到开发分支dev1时(两个不同的功能,不能合并),其他同事不知情的情况下,继续在dev1上开发并提交了代码. 后面发现了该合并, ...

  7. Git——快速重命名文件和查看commit提交版本【四】

    快速重命名文件 $ git mv README.md readme.md 使用git mv命令后直接commit即可,不再需要进行add或rm操作 查看版本历史 所有的参数都可以进行组合使用的,比如我 ...

  8. git查看commit提交记录详情

    相关的命令: git log:查看所有的commit提交记录: git show: 查看提交的详情: 首先,需要通过git log打印所有commit记录,例如: 1.查看最新的commit:git ...

  9. Git自动化合并多个Commit

    目录 git rebase逻辑 git editor的修改 处理git-rebase-todo文件 Python实现 当我们有多个commit或者从开源处拿到多个commit时,想合成一个commit ...

随机推荐

  1. Java设计模式の责任链模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述责任链(Chain of Responsibility)模式的: 责任链模式是一种对象的行为模式.在责任链模式里,很多对象由每一个对象对其 ...

  2. 树形dp的进阶 (一)

    ①树的重心的性质的运用 ②缩点以后寻找规律  树的直径! ③树形dp上的公式转换 ④和期望有关的树形dp + 一点排列组合的知识 ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ 一:Codeforces Round #364 ...

  3. 原生JS实现省市区(县)三级联动选择

    原文地址→看过来 写在前面 前段时间写一个关于天气的东西,里面的省市区(县)城市选择让我很头疼,在网上搜索出来大都是借助插件或者第三方库,感觉这样做代码会很重,所以索性就把几种城市选择的方式实现一遍, ...

  4. Codeforces Beta Round #34 (Div. 2) E. Collisions

    E. Collisions time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. 通过jquery.validate.js校验表单字段是否合法

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  6. ES6核心,值得驻足花一天时间来学习

    1.let 和 const 命令 在es5时,只有两种变量声明,var 和function.在es6中新增了四种let和const,以及另外两种声明import和class. 我们先讲解let和con ...

  7. 【leetcode 简单】第四十一题 Excel表列序号

    给定一个Excel表格中的列名称,返回其相应的列序号. 例如, A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...

  8. 【leetcode 简单】第十五题 加一

    给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. 示例 1: ...

  9. Markdown tutorial [repost]

    1. italic We'll start by learning two basic elements in text formatting: italics and bold. In these ...

  10. three.js_sence(场景)

    1,THREE.Scene 的作用 (1)THREE.Scene 对象是所有不同对象的容器,也就是说该对象保存所有物体.光源.摄像机以及渲染所需的其他对象. (2)THREE.Scene 对象又是被称 ...