📜  git show last commit - Shell-Bash (1)

📅  最后修改于: 2023-12-03 14:41:27.724000             🧑  作者: Mango

Git Show Last Commit - Shell/Bash

As a programmer, you might often need to review the last commit you made to a Git repository. In such cases, the git show command comes in handy. It displays all the details about the latest commit, including the commit message, author, timestamp, and the changes made.

Syntax

The syntax to show the last commit in a Git repository using the git show command is as follows:

git show HEAD

Here, HEAD refers to the latest commit in the repository.

Example

Suppose you have made a few changes to your code and committed them to the Git repository. To view the latest commit details, you need to run the following command:

git show HEAD

The output of this command will look something like this:

commit 1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0a1b
Author: John Doe <johndoe@example.com>
Date:   Thu Sep 23 12:35:21 2021 -0400

    Added new feature

diff --git a/src/main/java/com/example/App.java b/src/main/java/com/example/App.java
index 1234567..98a7b6c 100644
--- a/src/main/java/com/example/App.java
+++ b/src/main/java/com/example/App.java
@@ -1,4 +1,4 @@
 package com.example;
 
-public class App
+public class App2
 {
     public static void main( String[] args )
     {
-        System.out.println( "Hello World!" );
+        System.out.println( "Hello World 2!" );
     }
 }

Here, the commit line shows the unique ID of the commit, and Author line shows the name and email of the person who made the commit. The Date line shows the timestamp of the commit.

The diff lines show the differences made to the code in this commit. In this example, the App class has been modified to print a different message.

Conclusion

In summary, the git show HEAD command is useful for reviewing the details of the latest commit made to a Git repository. It provides a lot of useful information, including the commit message, author, timestamp, and changes made. As a programmer, you will find this command useful for debugging and reviewing the code changes you make.