[Practical Git] Filter commit history with git log arguments

Source: Internet
Author: User

In the last lesson, we learned how to format the git log output; In this lesson we'll learn how to filter down to a specific set of commits. By default, git log shows every commits in a repo.  We'll walk through using a bunch of options to the filter our Git log commits to a more meaningful set (,,, -n --after --before --author--grep-S-G--no-merges{ref}..{ref}{files}). We'll also show how all of the formatting and filtering options can is composed together to query exactly what is L Ooking for with your commit history.

Show Lasat N Commit:

Git log-3//  Show last three commit

Show commits from a center time:

git log--after="yesterday"//Show the commit between yesterday and today
git log--after="minutes ago"--after="2 weeks ago"  --after="3/15/16"//  Match.

Combine with--before:

git log--after="3/15/16" --before="yesterday"

The same as:

git log--since="3/15/16" --until="yesterday"

Filter by Author:

git log--author="tavor"

Filter by the commit message:

git log--grep="copyright"

Filter by the code using string:

git log-s"math.random"//  get all the commit which have math.random changes in the Code, and Use-p option to see the code

Filter by the code using Regex:

// Using ' G ' without quotes and follow with regex math or random

Ingore the case:

git log-i--author="Jane"//  search both for "Jane" and "Jane"-- author="Jane"// search only for "Jane"

Filter out Merges commit:

git log--no-merges

See the commits between-branch:

git log master. Cool-feature

Search by files:

// Search for Lience and Readme files

Example:

Git log-3 readme.md-p-i--author="tavor"// want to sees last 3 change o n readme.md file by author Tavor, ignor the case, and show the code
git log-s"Math" --after="2 months ago" --oneline-- Stat

[Practical git] Filter commit history with Git log arguments

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.