Git and GitHub – Log and Show Command in Git (Part-4)

Posted by

Git Log

Command: git log

Purpose: The git log command displays a list of commits in your repository, showing information about each commit such as the commit hash, author, date, and commit message.

Basic Usage:

git log

Example:

$ git log
commit 7062f9ba83b7f96f3b722be237935c0c30ac5de4 (HEAD -> master)
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 16:07:13 2024 -0700

    all

commit 3d0f84561e39cdfc6724c77b2b135e245dc6bf22
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 16:05:15 2024 -0700

    file1

commit ba9fae72620636a02321a558cc71836bad99ca0f
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 15:29:34 2024 -0700

    Adding first commit

Explanation:

  1. Commit Hash: Each commit has a unique identifier (e.g., 7062f9ba83b7f96f3b722be237935c0c30ac5de4).
  2. Author: The name and email of the person who made the commit.
  3. Date: The date and time when the commit was made.
  4. Commit Message: A brief description of the changes made in the commit (e.g., all, file1, Adding first commit).

Git Show

Command: git show

Purpose: The git show command provides detailed information about a specific commit, including the changes made, who made the changes, and when.

Basic Usage:

git show <commit-hash>

Example:

$ git show 7062f9ba83b7f96f3b722be237935c0c30ac5de4
commit 7062f9ba83b7f96f3b722be237935c0c30ac5de4 (HEAD -> master)
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 16:07:13 2024 -0700

    all

diff --git a/file1.txt b/file1.txt
new file mode 100644
index 0000000..e69de29

Explanation:

  1. Commit Hash: The unique identifier for the commit.
  2. Author: The name and email of the person who made the commit.
  3. Date: The date and time of the commit.
  4. Commit Message: A brief description of the changes.
  5. Diff: The actual changes made in the commit. This section shows which files were added, deleted, or modified.

Step-by-Step Example Using git log and git show

  1. Check the Last Commit Log:
git log -1

This command will display the most recent commit.

Output:

commit 7062f9ba83b7f96f3b722be237935c0c30ac5de4 (HEAD -> master)
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 16:07:13 2024 -0700

    all

Check Detailed Log for a Specific Commit:

git show 7062f9ba83b7f96f3b722be237935c0c30ac5de4

This command will display detailed information about the commit with the hash 7062f9ba83b7f96f3b722be237935c0c30ac5de4.

Output:

commit 7062f9ba83b7f96f3b722be237935c0c30ac5de4 (HEAD -> master)
Author: Jami Raj <jami.cotocus@gmail.com>
Date:   Tue May 28 16:07:13 2024 -0700

    all

diff --git a/file1.txt b/file1.txt
new file mode 100644
index 0000000..e69de29

Purpose: This command provides detailed information about the commit with the hash 7062f9ba83b7f96f3b722be237935c0c30ac5de4, including the changes made in that commit.

using git log and git show, you can inspect the history of your project, understand who made changes, what changes were made, and when they were made. This helps in tracking the development progress, debugging issues, and collaborating effectively with other developers.

guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x