在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. 如何将html5程序打包成Android应用

    问题分析: html5网站主要由html+css+js的形式组成,需要使用浏览器进行展现. Android需要使用Java语言来开发,对于前端工程师来说,无疑是增加了很大的难度. 随后出现了很多打包工 ...

  2. oracle实用的sqlplus命令

    有时候难免没有工具,得自己手动输入sqlplus命令 执行SQL文件:@sql文件,例如:@/home/myuser/sql/test.sql查看数据库存在的存储过程:Select object_na ...

  3. C++ string功能补充(类型互转,分割,合并,瘦身)

    int StringUtil::intFromString(string data) { //NOTE atoi是非标准C函数 return atoi(data.c_str()); } string ...

  4. 2049: [Sdoi2008]Cave 洞穴勘测

    2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 7475  Solved: 3499 [Submi ...

  5. 数学&模拟:随机化-矩阵随机化

    BZOJ2396 给出三个行数和列数均为N的矩阵A.B.C,判断A*B=C是否成立 随机生成一个N乘1的矩阵R 然后判断A*B*R是否等于C*R,而前者相当于A*(B*R) 与后者一样都可以在O(N2 ...

  6. CSS 文本属性

    一.文本位置 text-align: 参数 /** * left center right:左中右**/text-align: left; 二.文本行间距 line-height: 参数 特别要注意: ...

  7. MySQL异常总结

    1.Packets larger than max_allowed_packet are not allowed MySQL的一个系统参数:max_allowed_packet,其默认值为104857 ...

  8. 拦截asp.net输出流做处理

    本文标题是指对已经生成了HTML的页面做一些输出到客户端之前的处理. 方法的原理是:把Response的输出重定向到自定义的容器内,也就是我们的StringBuilder对象里,在HTML所有的向页面 ...

  9. 移动端meta声明

    <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --><html lang="zh-cmn-Hans"> ...

  10. A .Gaby And Addition (Gym - 101466A + 字典树)

    题目链接:http://codeforces.com/gym/101466/problem/A 题目: 题意: 给你n个数,重定义两个数之间的加法不进位,求这些数中两个数相加的最大值和最小值. 思路: ...