在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. 改变 jq中 data-id 的值

    if (_this.hasClass('default_btn_is')){ _this.removeClass('default_btn_is'); _this.addClass('default_ ...

  2. libcurl移植到android

    一.总体概览 C库:libcurl 3.7 目标平台:android 编译平台:ubuntu 12 编译工具:ndk r7 or later 二.已知方法 1. 官网上给了两种方法,第一种方法是使用a ...

  3. Maven将java项目打包生成可运行jar

    Maven将java项目打包生成可运行jar Maven插件配置 <plugins> <plugin> <groupId>org.apache.maven.plug ...

  4. [USACO07FEB] Lilypad Pond

    https://www.luogu.org/problem/show?pid=1606 题目描述 FJ has installed a beautiful pond for his cows' aes ...

  5. 2015/9/21 Python基础(17):绑定和方法调用

    绑定和方法调用现在我们需要再次阐述Python中绑定(binding)的概念,它主要与方法调用相关联.方法是类内部定义的函数,这意味着方法是类属性而不是实例属性.其次,方法只有在其所属的类拥有实例时, ...

  6. TED_Topic1:Why we need to rethink capitalism

    Topic 1:Why we need to rethink capitalism By Paul Tudor Jones II # Background about our speaker      ...

  7. POJ 1050 To the Max (最大子矩阵和)

    题目链接 题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和. 题解:把二维转化成一维,算下就好了. #include <cstdio> #include <cstring> ...

  8. 天梯赛 L2-005 集合相似度 (set容器)

    给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.其中Nc是两个集合都有的不相等整数的个数,Nt是两个集合一共有的不相等整数的个数.你的任务就是计算任意一对给定集合的相似度. 输入格式: 输 ...

  9. Shader -> Photoshop图层混合模式计算公式大全

    Photoshop图层混合模式计算公式大全 混合模式可以将两个图层的色彩值紧密结合在一起,从而创造出大量的效果,在这些效果的背后实际是一些简单的数学公式在起作用. 下面是photoshop cs2中所 ...

  10. 关于"轉淚點"与"轉捩點"

    经常看台湾偶像剧或台湾综艺节目的人,一定听过"转泪点"这个词,虽然我一直不知道这三个字具体是怎么写, 但其意思很容易明白,就是"转折点"的意思.今天无聊在看凤凰 ...