31 Filtering the Log Output

Git’s log is useful way to track what the original developer—often yourself—was thinking when they made a change, but it often provides too much information. You can use git log’s many parameters to filter the results it displays, zeroing in on the information that’s important to you.

You can start to filter the results by providing Git with a directory or path. You specify the path as the last parameter. To be safe, separate the path from other parameters with -- (two dashes). Otherwise, Git can’t tell the difference between the branch or tag work and the path work.

You can also filter the log based on the time of the commit. Using the --since or --after parameter, you can look at commits after a given point in time. Git attempts to parse any string you give it but fails silently if it can’t parse the date you provide. Stick with traditional date and time formats or a number followed by months, weeks, days, hours, minutes, and so on, to make sure Git can understand you.

Git provides you with the opposite of --since and --after too; you can use --until or --before to look for commits older than a given time.

You use --author to filter the results by author or email address. Git matches on a partial name; --author="Travis" match both the commits I make and commits authored by “The Other Travis.”

Finally, you can use --grep to search through the log messages using a regular expression, or regexp. It uses basic regular expressions, just like the command-line tool it takes its name from—grep. You can tell it to ignore case with the --regexp-ignore-case or the shorter -i parameters.

What To Do...
  • Limit the log output to a single file or directory.
     
    prompt>​ git log -- some/path/
     
    prompt>​ git log -- some_file
  • View the commits in the last week.

    You can use many kinds of times with --since or --after. Here are a few variations of looking at the last week of commits:

     
    prompt>​ git log --since="1 week"
     
    ...​ or ...
     
    prompt>​ git log --after="7 days"
     
    ...​ or ...
     
    prompt>​ git log --since="168 hours"
  • View the commits prior to the last week.
     
    prompt>​ git log --before="1 week"
     
    ...​ or ...
     
    prompt>​ git log --until="7 days"
     
    ...​ or ...
     
    prompt>​ git log --before="168 hours"
  • View the log entries by a single committer.
     
    prompt>​ git log --author="some user"
  • View the log entries containing a regular expression.
     
    prompt>​ git log --grep="some [Rr]eg[Ee]x"
     
    ...​ or ...
     
    prompt>​ git log --grep="some regex" --regexp-ignore-case
     
    ...​ or ...
     
    prompt>​ git log --grep="some regex" -i

Related Tasks

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.195.111