git如何查看提交版本
-
要查看Git的提交版本,你可以使用以下命令:
1. `git log`:这个命令会显示仓库的提交历史。默认情况下,它会按照最新的提交显示在最上面,按照时间顺序显示。每个提交都包括提交作者、日期和提交信息。
“`
$ git log
commit 442719b601d9f9c2a7ae3f55bd7d1a5d8725c1cc (HEAD -> master)
Author: John Doe
Date: Mon Nov 23 15:29:51 2020 -0500Add new feature
commit 9f4c86bedc2a8301a8950e24c36b6bc5f79bc5ef
Author: John Doe
Date: Sun Nov 22 09:13:47 2020 -0500Update README.md
…
“`2. `git show
`:这个命令可以显示指定提交的详细信息,包括更改的文件、修改的内容等。 “`
$ git show 442719b601d9f9c2a7ae3f55bd7d1a5d8725c1cc
commit 442719b601d9f9c2a7ae3f55bd7d1a5d8725c1cc (HEAD -> master)
Author: John Doe
Date: Mon Nov 23 15:29:51 2020 -0500Add new feature
diff –git a/file1.txt b/file1.txt
index 4ee7ef2..6470751 100644
— a/file1.txt
+++ b/file1.txt
@@ -1,3 +1,4 @@
This is file 1.
Some content here.
+New feature added.
“`3. `git diff
`:这个命令可以比较两个提交之间的差异。你可以使用具体的提交哈希值或者分支名作为参数。 “`
$ git diff 9f4c86b 442719b
diff –git a/file1.txt b/file1.txt
index 4ee7ef2..6470751 100644
— a/file1.txt
+++ b/file1.txt
@@ -1,3 +1,4 @@
This is file 1.
Some content here.
-New feature added.
+New feature added in second commit.
“`这些命令可以帮助你查看Git仓库的提交版本信息。
2年前