🐙
Git Developer Guide
About
  • Overview
  • Scope of this book
  • Table of Content
  • 🐢Introduction to Version Control
    • What is Version Control?
    • Overview of git and it's benefits
    • Setting up Git on Different Platforms
  • 🍼Git Fundamentals
    • Initialising a new Git repository
    • Understanding the Git Workflow
    • Committing Changes and Writing Good Commit Messages
    • Viewing and Navigating Commit History
    • Git Basics - Practice Scenarios
      • Initialising a Git Repository
      • Committing Changes
      • Exploring Commit History
      • Amending and Undoing Commits
  • 🦕Working With Git
    • What is Git Branch?
    • Creating and Switching Between Branches
    • Merging Branches and Resolving Conflicts
    • Best Practices for Branch Management
    • Git Workflows
    • Git Log
    • Git Stash
    • Working with Git - Practice Scenarios
      • Creating and Switching Between Branches
      • Merging Branches and Resolving Conflicts
      • Branching Strategies in a Team Project
      • Rolling Back to a Previous Version
      • Experimenting with Feature Branches
      • Working with Stash
  • 🤝Working with Remote Repositories
    • Cloning a Repository from Remote
    • Pushing and Pulling Changes to and from Remote Repositories
    • Collaborative Workflows - Forking, Branching, and Pull Requests
    • Resolving Conflicts in a Collaborative Environment
    • Collaborating with Git - Practice Scenarios
      • Cloning a Remote Repository
      • Pushing and Pulling Changes
      • Collaborative Workflow with Forking and Pull Requests
      • Resolving Conflicts in a Pull Request
  • 🏆Advanced Git Features
    • Aliases and Custom Configurations
    • Working with Tags and Releases
    • Rewriting Commit History with Interactive Rebase
    • Utilising Git Hooks for Automation
    • Advanced Git Features - Practice Scenarios
      • Creating Custom Git Aliases
      • Working with Tags and Releases
      • Rewriting Commit History with Interactive Rebase
      • Using Git Hooks for Automated Testing
  • 😎Git in Real-World
    • Managing a Project with Multiple Contributors
    • Integrating Git with Continuous Integration, Continuous Deployment (CI, CD)
    • Versioning Assets with Git LFS (Large File Storage)
    • Deploying a Web Application using Git
    • Git In Real World - Practice Scenarios
      • Managing a Project with Multiple Contributors
      • Integrating Git with CICD Pipelines
      • Versioning Assets with Git LFS
      • Deploying a Web Application using Git
  • Git Troubleshooting
    • Common Mistakes and Pitfalls When Using Git
    • Undoing Changes with Git - Reverting and Resetting
    • Recovering Lost Commits or Branches
    • Dealing with Repository Corruption or Other Issues
  • Git Best Practices and Tips
    • Creating efficient git workflows: writing clean code for faster reviews
    • The importance of clean code in collaborative development
    • Significance of consistent naming conventions & coding Standards
    • Good code documentation for better git workflows
    • Writing meaningful git commit messages
    • Atomic commits in git & it's benefits for software teams
    • Structuring code & managing dependencies for better git workflows
    • Git branching strategies for software teams
  • Conclusion & Next Steps
    • Recap of Key Concepts and Commands
    • Further Resources for Expanding Git Knowledge
    • Encouragement and Tips for Continued Learning and Practice
  • License Considerations
Powered by GitBook
On this page
  • Exploring different log formats and filtering options
  • Navigating through commit history using Git commands

Was this helpful?

  1. Git Fundamentals

Viewing and Navigating Commit History

In Git, the commit history provides valuable insights into the evolution of a project.

PreviousCommitting Changes and Writing Good Commit MessagesNextGit Basics - Practice Scenarios

Last updated 1 year ago

Was this helpful?

The git log command allows you to view this history in various ways, enabling you to understand when changes were made, who made them, and what exactly was changed. In this section, we will explore the git log command and its options for displaying commit history.

Basic git log command

To start with, you can simply run git log in your terminal to view the commit history of the current branch. By default, it shows a chronological list of commits, starting with the most recent one.

git log

Limiting the number of commits

If the commit history is extensive, you may want to limit the number of commits displayed. The --max-count option allows you to specify the maximum number of commits to show.

git log --max-count=5

Displaying commit details

The default git log output shows each commit's SHA-1 hash, author, date, and commit message. However, you can customise the log format to display additional information such as the commit's diff.

git log --stat

Formatting the output

Git provides flexible options to format the output of git log. You can use placeholders to include specific information, such as the commit hash (%H), author name (%an), commit message subject (%s), etc. Here's an example that displays a custom log format:

git log --pretty=format:"%h - %an, %ar : %s"

For more information on customising the log format, you can refer to the .


Exploring different log formats and filtering options

In this section, we will delve deeper into the log format options provided by Git and explore various filtering options to narrow down the commit history.

Graphical representation of commits:

To visualise the branching and merging in your commit history, you can use the --graph option along with git log. This provides a more intuitive representation of the commit graph.

git log --graph

Showing the commit diff

To see the detailed changes made in each commit, you can use the --patch or -p option. It displays the diff associated with each commit.

git log -p

Filtering commits by author

If you're interested in viewing the commits made by a specific author, you can use the --author option followed by the author's name or email.

git log --author="John Doe"

Filtering commits by date range

Git allows you to filter commits based on a specific date range. The --since and --until options are used for this purpose.

git log --since="2023-01-01" --until="2023-06-01"

Searching for commits by keywords

To find commits containing specific keywords in the commit message, you can use the --grep option followed by the keyword(s).

git log --grep="bug fix"

Navigating through commit history using Git commands

In this section, we will explore various Git commands that help you navigate through the commit history.

Checking out a specific commit

To inspect the codebase as it was at a particular commit, you can use the git checkout command followed by the commit hash. This places your repository in a "detached HEAD" state.

git checkout <commit-hash>

Creating a branch from a specific commit

If you want to create a branch starting from a specific commit, you can use the git branch command followed by the branch name and the commit hash.

git branch <branch-name> <commit-hash>

Comparing commits

Git provides several ways to compare different commits. For example, you can use the git diff command followed by two commit hashes to see the differences between them.

git diff <commit-hash1> <commit-hash2>

Moving through commit history

Git allows you to move through the commit history using relative references. For instance, you can use HEAD~1 to refer to the previous commit and HEAD~2 for the commit before that.

git log HEAD~3..HEAD

This command displays the commit history from the commit three steps before HEAD to the current HEAD.

By understanding how to view, format, and filter commit history using git log, as well as utilizing other Git commands for navigation, you gain a powerful toolset for exploring the evolution of your project and understanding the changes made over time.

🍼
Git documentation on pretty formats