This article details methods to view Git commit information. It explores commands like git log, git rev-parse HEAD, and git show to display commit hashes, author, date, message, and changes. Various formatting options are also presented for customi
This question refers to how to see the commit information of the HEAD commit, which is the latest commit on your current branch. There are several ways to achieve this. The simplest is using git log
with the --oneline
flag for a concise view, or without any flags for a more detailed view.
<code class="bash">git log --oneline # or git log</code>
git log --oneline
will show a short hash and the commit message for each commit, making it easy to identify the current commit at the top of the output. git log
without any flags provides a more detailed view, including author, date, and a full commit message.
The commit hash uniquely identifies a specific commit in your Git repository. To see the commit hash of the current branch's HEAD (latest) commit, you can use several commands. The simplest and most direct is:
<code class="bash">git rev-parse HEAD</code>
This command will output the full 40-character SHA-1 hash of the current commit. Alternatively, you can also use git log --pretty=format:"%H"
which will output only the commit hash. This is useful if you want to extract the hash for scripting purposes. Finally, a shortened hash can be obtained (though not recommended for absolute certainty) using git log --oneline
as mentioned above.
git show
The git show
command is a powerful tool that displays information about a commit. When used without arguments, it displays information about the current commit (HEAD). The information includes:
git show
, as it visually represents the changes.For example, git show
will output something similar to this:
<code>commit <commit-hash> Author: Your Name <your.email@example.com> Date: Wed Sep 27 14:30:00 2023 -0700 Commit message here diff --git a/file1.txt b/file1.txt index <hash>..<hash> 100644 --- a/file1.txt +++ b/file1.txt @@ -1,2 +1,3 @@ This is a line. +This is a new line. This is another line.</code>
To find the author and date of the current commit, several Git commands can be used. The simplest is git show
, as explained above. This command provides both pieces of information in its output.
Alternatively, you can use git log
with appropriate formatting options. For example:
<code class="bash">git log -1 --pretty=format:"Author: %an%nDate: %ad" --date=short</code>
This command displays only the first commit (using -1
), formats the output to show only the author name (%an
) and date (%ad
with --date=short
for a concise date format), and separates them with a newline character (%n
). The output will be similar to:
<code>Author: Your Name Date: 2023-10-27</code>
These commands provide various ways to access the crucial information about your current commit, allowing for efficient version control management.
以上がgit現在のコミットを表示する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。