Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1199696
  • 博文数量: 185
  • 博客积分: 495
  • 博客等级: 下士
  • 技术积分: 1418
  • 用 户 组: 普通用户
  • 注册时间: 2012-09-02 15:12
个人简介

治肾虚不含糖,专注内核性能优化二十年。 https://github.com/KnightKu

文章分类

全部博文(185)

文章存档

2019年(1)

2018年(12)

2017年(5)

2016年(23)

2015年(1)

2014年(22)

2013年(82)

2012年(39)

分类: LINUX

2013-04-23 11:33:23

如果你要查看文件的每个部分是谁修改的, 那么 就是不二选择. 只要运行'git blame [filename]', 你就会得到整个文件的每一行的详细修改信息:包括commit SHA串,日期和作者:

[root@guz linux-2.6]# git blame kernel/cgroup.c 
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    1) /*
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    2)  *  Generic process-grouping system.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    3)  *
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    4)  *  Based originally on the cpuset system, extracted 
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    5)  *  Copyright (C) 2006 Google, Inc
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700    6)  *
0dea1168 (Kirill A. Shutemov   2010-03-10 15:22:20 -0800    7)  *  Notifications support
0dea1168 (Kirill A. Shutemov   2010-03-10 15:22:20 -0800    8)  *  Copyright (C) 2009 Nokia Corporation
0dea1168 (Kirill A. Shutemov   2010-03-10 15:22:20 -0800    9)  *  Author: Kirill A. Shutemov
0dea1168 (Kirill A. Shutemov   2010-03-10 15:22:20 -0800   10)  *
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   11)  *  Copyright notices from the original cpuset code:
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   12)  *  -------------------------------------------------
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   13)  *  Copyright (C) 2003 BULL SA.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   14)  *  Copyright (C) 2004-2006 Silicon Graphics, Inc.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   15)  *
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   16)  *  Portions derived from Patrick Mochel's sysfs code
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   17)  *  sysfs is Copyright (c) 2001-3 Patrick Mochel
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   18)  *
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   19)  *  2003-10-10 Written by Simon Derr.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   20)  *  2003-10-22 Updates by Stephen Hemminger.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   21)  *  2004 May-July Rework by Paul Jackson.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   22)  *  -------------------------------------------------
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   23)  *
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   24)  *  This file is subject to the terms and conditions 
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   25)  *  License.  See the file COPYING in the main direct
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   26)  *  distribution for more details.
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   27)  */
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   28) 
ddbcc7e8 (Paul Menage          2007-10-18 23:39:30 -0700   29) #include  

如果文件被修改了(reverted),或是编译(build)失败了; 这个命令就可以大展身手了.

你也可以用"-L"参数在命令(blame)中指定开始和结束行:

[root@guz linux-2.6]# git blame -L1400,1410 kernel/cgroup.c 
cc31edce (Paul Menage        2008-10-18 20:28:04 -0700 1400) {
cc31edce (Paul Menage        2008-10-18 20:28:04 -0700 1401)    INIT_LIST_HEAD(&cgrp->sibling);
cc31edce (Paul Menage        2008-10-18 20:28:04 -0700 1402)    INIT_LIST_HEAD(&cgrp->children);
05ef1d7c (Tejun Heo          2012-04-01 12:09:56 -0700 1403)    INIT_LIST_HEAD(&cgrp->files);
cc31edce (Paul Menage        2008-10-18 20:28:04 -0700 1404)    INIT_LIST_HEAD(&cgrp->css_sets);
2243076a (Tejun Heo          2012-11-19 08:13:35 -0800 1405)    INIT_LIST_HEAD(&cgrp->allcg_node);
cc31edce (Paul Menage        2008-10-18 20:28:04 -0700 1406)    INIT_LIST_HEAD(&cgrp->release_list);
72a8cb30 (Ben Blum           2009-09-23 15:56:27 -0700 1407)    INIT_LIST_HEAD(&cgrp->pidlists);
be445626 (Li Zefan           2013-01-24 14:31:42 +0800 1408)    INIT_WORK(&cgrp->free_work, cgroup_free_fn);
72a8cb30 (Ben Blum           2009-09-23 15:56:27 -0700 1409)    mutex_init(&cgrp->pidlist_mutex);
0dea1168 (Kirill A. Shutemov 2010-03-10 15:22:20 -0800 1410)    INIT_LIST_HEAD(&cgrp->event_list);

更多强大功能参见man git-blame 
GIT-BLAME(1)                                        Git Manual                                       GIT-BLAME(1)

NAME
       git-blame - Show what revision and author last modified each line of a file

SYNOPSIS
       git blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-e] [-p] [-w] [--incremental] [-L n,m]
                   [-S ] [-M] [-C] [-C] [-C] [--since=] [--abbrev=]
                   [ | --contents | --reverse ] [--]

DESCRIPTION
       Annotates each line in the given file with information from the revision which last modified the line.
       Optionally, start annotating from the given revision.

       The command can also limit the range of lines annotated.

       The report does not tell you anything about lines which have been deleted or replaced; you need to use a
       tool such as git diff or the "pickaxe" interface briefly mentioned in the following paragraph.

       Apart from supporting file annotation, git also supports searching the development history for when a code
       snippet occurred in a change. This makes it possible to track when a code snippet was added to a file,
       moved or copied between files, and eventually deleted or replaced. It works by searching for a text string
       in the diff. A small example:

           $ git log --pretty=oneline -S'blame_usage'
           5040f17eba15504bad66b14a645bddd9b015ebb7 blame -S
           ea4c7f9bf69e781dd0cd88d2bccb2bf5cc15c9a7 git-blame: Make the output

SPECIFYING RANGES
       Unlike git blame and git annotate in older versions of git, the extent of the annotation can be limited to
       both line ranges and revision ranges. When you are interested in finding the origin for lines 40-60 for
       file foo, you can use the -L option like so (they mean the same thing — both ask for 21 lines starting at
       line 40):

           git blame -L 40,60 foo
           git blame -L 40,+21 foo

       Also you can use a regular expression to specify the line range:

           git blame -L '/^sub hello {/,/^}$/' foo

       which limits the annotation to the body of the hello subroutine.

       When you are not interested in changes older than version v2.6.18, or changes older than 3 weeks, you can
       use revision range specifiers similar to git rev-list:

           git blame v2.6.18.. -- foo
           git blame --since=3.weeks -- foo

       When revision range specifiers are used to limit the annotation, lines that have not changed since the
       range boundary (either the commit v2.6.18 or the most recent commit that is more than 3 weeks old in the
       above example) are blamed for that range boundary commit.

       A particularly useful way is to see if an added file has lines created by copy-and-paste from existing
       files. Sometimes this indicates that the developer was being sloppy and did not refactor the code
       properly. You can first find the commit that introduced the file with:

           git log --diff-filter=A --pretty=short -- foo

       and then annotate the change between the commit and its parents, using commit^! notation:

           git blame -C -C -f $commit^! -- foo




阅读(1551) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~