Tag: Git Log

  • Git Log Author

    Git Log Author

    If you’re a Git user, you’re likely familiar with the git log command, which allows you to view the commit history for a repository. This blog post is an extra tip on the git log command, showing the --author option parameter which allows you to filter the commits displayed by the author’s name.

    This can be particularly useful if you are working on a large project with multiple contributors and want to see only the commits made by a specific person.

    Show Commits by Author in Git

    To use the –author option, simply pass the name of the author as an argument when running the git log command.

    For example, if you only want to see the commits made by “pete”, you would run the following command:

    git log --author="pete"
    

    Hit ‘q‘ to exit out of the git log return feed.

    We can also use the git one-line parameter while searching commits for an author, with a wildcard:

    git log --author="Sukki*" --oneline
    

    This will display a list of commits, each on a single line, with the author, commit message, and SHA hash of the commit.

    The git log command has options that allow you to tailor the information it displays. For example, you can use the –oneline parameter, which I covered in another blog post (including git log formatting).

  • Git Log Command

    Git Log Command

    Git log is an essential command for working with Git. It allows you to see the history of a repository, including details about each commit like the author, date, and commit message.

    Using the git log command is simple. Just navigate to your Git repository in a terminal or command prompt and run the git log command. This will display a list of all the commits in your repository, starting with the most recent.

    $ git log
    commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
    Author: John Doe <john.doe@example.com>
    Date:   Tue Dec 1 13:45:26 2020 -0500
    
        Add new feature X
    
    commit a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2w3x4y5z6
    Author: Jane Smith <jane.smith@example.com>
    Date:   Mon Nov 30 12:15:43 2020 -0500
    
        Fix bug Y
    

    The git log command offers several options that allow you to tailor the information it displays. For instance, you can use the –oneline parameter, which I covered in another blog post (including git log formatting).

  • Git Log Show in One Line (–oneline)

    Git Log Show in One Line (–oneline)

    To check our commit history on a Repository within Git, we use the git log command. When using this command we scroll through the commit log within our Terminal by hitting the Enter key, and then we need to hit q on our keyboard to exit reading the git log.

    This post is to demo the --online parameter that can be added to the git log statement. Adding this parameter to the git log command will return a condensed commit log history, which shows the first part of the commit hash and message on one line.

    The following is included in this demo post:
    # Git Log
    # Git Log –OneLine
    # Git Log –OneLine -5
    # Git Log –OneLine with Custom Formatting

    Git Log

    In the following example, I’m running the standard git log command on one of my Repos. This is what we’d use if we want information including full commit hashes, commit dates/times, and authors.

    Git Log

    Git Log –Oneline

    This next example shows will return a condensed commit log history. It’s the same command as above but we’re adding the --oneline parameter.

    # Show git log in one line
    git log --oneline
    Git Log --oneline

    Git Log –Oneline -5

    You might think the above shows too many logs on the screen. We can pass in a line number parameter for it to return a specific number of commits.

    This next example shows with and without the above –oneline parameter. We limit the number of commits/rows being returned by adding ‘-5‘ (can be any number).

    # show most recent 2 commits
    git log -2
    
    # show most recent 5 commits on one line
    git log -5 --oneline
    Git Log -5

    Git Log –Oneline -5 with Custom Formatting

    We can amend the formatting of the returned list, including changing colours, adding in commit times, and adding the contributor.

    This would be ideal if it was added as a function on your Terminal Profile.

    # show most recent 5 commites on one line, with formatting
    git log -5 --graph --pretty=format:'%C(red)%h%Creset -%C(yellow)%d%Creset %s %C(green)(%cr) %C(yellow)<%an>%Creset'
    Git Log Formatting

    That’s it for this tip, check out my other posts on this topic in the Git Tag if of interest.