在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集合框架(set)

    set继承自collection接口,其子类和子接口如下: set的共同特性:不能添加相同的元素,通常无法记住元素添加的顺序 1.HashSet类 判断两元素相同的标准:1.equals方法返回tru ...

  2. [JSOI2010]Group

    1821: [JSOI2010]Group 部落划分 Group Time Limit: 10 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] De ...

  3. UVA 1647 Computer Transformation

    https://vjudge.net/problem/UVA-1647 题意: 开始有一个1,接下来每一步1变成01,0变成10 问n不之后00的个数 打表找规律 第3步之后: 如果第i步之后有x个字 ...

  4. POJ 2431 优先队列

    汽车每过一单位消耗一单位油,其中有给定加油站可加油,问到达终点加油的最小次数. 做法很多的题,其中优先对列解这题是很经典的想法,枚举每个加油站,判断下当前油量是否小于0,小于0就在前面挑最大几个直至油 ...

  5. Eng1—English daily notes

    English daily notes 2015年 4月 Phrases 1. As a side note #作为附注,顺便说句题外话,和by the way意思相近,例句: @1:As a sid ...

  6. 使用Forms Authentication

    using System; using System.Web; using System.Web.Security;   namespace AuthTest {   public class Aut ...

  7. 为什么需要 Stream

    Stream 作为 Java 8 的一大亮点,它与 java.io 包里的 InputStream 和 OutputStream 是完全不同的概念.它也不同于 StAX 对 XML 解析的 Strea ...

  8. matlab前景分割

    用最简单的差分法实现了一下前景分割.使用的mall数据集. 思路是这样的:首先设定一个队列的长度,若读取的图片张数少于队列长度则以当前读取到的图片做平均.否则则以队列中的图片做平均. 这样之后和当前图 ...

  9. VC连接access

    (1)首先拷贝 c:\program files\common files\system\ado\ 目录中的 msado15.dll 文件到项目中. (2)在VC中加入DLL,具体方法如下: (3)创 ...

  10. 64_n2

    nodejs-from-0.1.3-4.fc26.noarch.rpm 11-Feb-2017 15:01 9982 nodejs-from2-2.1.0-6.fc26.noarch.rpm 11-F ...