Ios-git View commit history (Distributed version control system)

Source: Internet
Author: User
Tags version control system

1. View Commit History
    • After you have submitted several updates, or cloned a project, you may want to review the submission history. The simplest and most effective tool for accomplishing this task is the git log command.

      $ git log
      commit ca82a6dff817ec66f44342007202690a93763949Author: Scott Chacon <[email protected]>Date:   Mon Mar 17 21:52:11 2008 -0700    changed the version numbercommit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7Author: Scott Chacon <[email protected]>Date:   Sat Mar 15 16:40:33 2008 -0700    removed unnecessary testcommit a11bef06a3f659402fe7563abf99ad00de2209e6Author: Scott Chacon <[email protected]>Date:   Sat Mar 15 10:31:28 2008 -0700    first commit    
    • By default, git log all updates are listed by time of submission, and most recent updates are on top. As you can see, this command lists each submitted SHA-1 checksum, the author's name and email address, the time of submission, and the submission instructions.

2. View a specific commit history 2.1 custom output format
  • git logCommon Options list The options that we currently have and are not involved in, and how they affect the output of the log command.

      选项             | 说明------------------|-------------------------------------------  -p              | 按补丁格式显示每个更新之间的差异  --stat          | 显示每次更新的文件修改统计信息  --shortstat     | 只显示 --stat 中最后的行数修改添加移除统计  --name-only     | 仅在提交信息后显示已修改的文件清单  --name-status   | 显示新增、修改、删除的文件清单  --abbrev-commit | 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符  --relative-date | 使用较短的相对时间显示(比如,“2 weeks ago”)  --graph         | 显示 ASCII 图形表示的分支合并历史  --pretty        | 使用其他格式显示历史提交信息
    • 1) A common option is to -p show the difference in content for each commit. This option, in addition to displaying the basic information, is accompanied by changes in each commit.

      $ git log -p -2
      Commit Ca82a6dff817ec66f44342007202690a93763949author:scott Chacon <[email protected]>date:mon Mar 17 21:52:11 2008-0700 changed the version numberdiff--git a/rakefile b/rakefileindex a874b73. 8f94139 100644---a/rakefile+++ b/rakefile@@ -5,7 +5,7 @@ require ' rake/gempackagetask ' spec = gem::specification.new do |     s| S.platform = Gem::P latform::ruby s.name = "Simplegit"-s.version = "0.1.0" + s.version = "0.1.1 "S.author =" Scott Chacon "s.email =" [email protected] "s.summary =" A simple gem for us ing Git in Ruby code. " Commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7author:scott Chacon <[email protected]>date:sat Mar 15 16:40:33 2008-0700 removed unnecessary testdiff--git a/lib/simplegit.rb b/lib/simplegit.rbindex a0a60ae. 47c6340 100644---a/lib/simplegit.rb+++ b/lib/simplegit.rb@@ -18,8 +18,3 @@ class Simplegit end end--if $ = __file __-git = simplegit.new-puts git.show-end\ No newline at end of file   
    • 2) you want to see the summary statistics for each submission, you can use the --stat option. All the modified files are listed below each commit, how many files have been modified, and which lines of the modified files have been removed or added. There is a summary at the end of each submission.

        $ git log--stat  
        commit Ca82a6dff817ec66f44342007202690a93763949author:scott Chacon <[email protected]>date:mon Mar 21:52:11 2008-0700 changed the version number Rakefile | 2 +-1 file changed, 1 insertion (+), 1 deletion (-) Commit 085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7author:scott Chacon < [Email protected]>date:sat Mar 16:40:33 2008-0700 removed unnecessary test LIB/SIMPLEGIT.RB | 5-----1 File changed, 5 deletions (-) Commit A11bef06a3f659402fe7563abf99ad00de2209e6author:scott Chacon <[email&  Nbsp;protected]>date:sat Mar 10:31:28 2008-0700 First Commit README | 6 ++++++ Rakefile | +++++++++++++++++++++++ LIB/SIMPLEGIT.RB | +++++++++++++++++++++++++ 3 files changed, insertions (+)  
    • 3) Another common option is --pretty . This option specifies that the commit history will be displayed in a different way than the default format. This option has some built-in sub-options for you to use. For example, using oneline to put each commit on one line, it is useful to see a large number of commits. In addition, Short,full and fuller can be used, the information displayed is more or less different.

      $ git log --pretty=oneline
      ca82a6dff817ec66f44342007202690a93763949 changed the version number085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7 removed unnecessary testa11bef06a3f659402fe7563abf99ad00de2209e6 first commit
    • But the most interesting thing is format that you can customize the format of the records to be displayed. This output is particularly useful for post-extraction analysis

      $ git log --pretty=format:"%h - %an, %ar : %s"
      ca82a6d - Scott Chacon, 6 years ago : changed the version number085bb3b - Scott Chacon, 6 years ago : removed unnecessary testa11bef0 - Scott Chacon, 6 years ago : first commit
    • The commonly used options for
    • git log--pretty=format list the commonly used format placeholder notation and the meaning it represents.

        Options | Description------|-------------------------------------%H | Full hash string for commit (commit)%h | Short hash string for the Commit object%T | Full hash string%t of tree Object | Short hash string for tree object%P | Full hash string%p of Parent Object | Short hash string for parent object%an | The name of the author (author)%ae | Author's email address%ad | Author revision date (can be customized with--date= option)%ar | Author revision date, as of how long ago the Way show%CN | The name of the submitter (committer)%ce | Submitter's email address%CD | Date of submission%CR | Date of submission, how long before the way the%s was displayed | Submission Description  
    • This is especially useful when oneline or format is used in conjunction with another log option --graph . This option adds some ASCII strings to visualize your branch and merge history.

      $ git log --pretty=format:"%h %s" --graph
      * 2d3acf9 ignore errors from SIGCHLD on trap*  5e3ee11 Merge branch 'master' of git://github.com/dustin/grit|| * 420eac9 Added a method for getting the current branch.* | 30e367c timeout code and tests* | 5a09431 add timeout protection to grit* | e1193f8 support for heads with slashes in them|/* d6016bc require time for xmlschema*  11d191e Merge branch 'defunkt' into local  
2.2 Limit output length
  • In addition to the options for customizing the output format, git log There are many useful options to limit the length of the output, which is to output only part of the commit information.

      选项               | 说明--------------------|-----------------------------  -(n)              | 仅显示最近的 n 条提交  --since, --after  | 仅显示指定时间之后的提交。  --until, --before | 仅显示指定时间之前的提交。  --author          | 仅显示指定作者相关的提交。  --committer       | 仅显示指定提交者相关的提交。  --grep            | 仅显示含指定关键字的提交  -S                | 仅显示添加或移除了某个关键字的提交
    • 1) You've seen it before -2 , it shows only the last two commits, in fact, this is the -<n> notation, where n can be any integer that shows only the last few commits. However, in practice we are not using this option, Git will automatically invoke the paging program when outputting all commits, so you will only see one page of content at a time.

    • 2) There are also options that are limited by time, such as --since and --until also useful. This command can work in a variety of formats, such as a specific day "2008-01-15", or a relative how long ago "2 years 1 days 3 minutes ago".

      $ git log --since=2.weeks
    • 3) You can also give some search criteria to list the submissions that are eligible. --authorDisplays the submission of the specified author with options and --grep searches for the keywords in the submission description with options. (Note that if you want to have a commit that satisfies both of these options, you must use an --all-match option.) Otherwise, commits that satisfy any one of the conditions will be matched).

    • 4) Another very useful filtering option is -S to list commits that have added or removed certain strings. For example, if you want to find a commit that adds or removes a reference to a particular function, you can use that.

      $ git log -Sfunction_name      
    • 5) The last useful git log option is path, and if you only care about the historical submission of certain files or directories, you can git log specify their paths at the end of the options. Because it is the option placed in the last position, the previous option and the qualified path name are separated by two dashes (--).

    • To see a practical example, if you want to view the Git repository during October 2008, Junio Hamano submitted but not merged test files, you can use the following query command.

      $ git log --pretty="%h - %s" --author=gitster --since="2008-10-01"  --before="2008-11-01" --no-merges -- t/
      5610e3b - Fix testcase failure when extended attributes are in useacd3b9e - Enhance hold_lock_file_for_{update,append}() APIf563754 - demonstrate breakage of detached checkout with symbolic link HEADd1a43f2 - reset --hard/read-tree --reset -u: remove unmerged new paths51a94af - Fix "checkout --track -b newbranch" on detached HEADb0ad11e - pull: allow "git pull origin $something:$current_branch" into an unborn branch

Ios-git View commit history (Distributed version control system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.