目录
描述
在不确定版本仓库是否有修改的情况下,使用Git命令来查看仓库改动和修改详情。
git status:查看仓库状态
git status命令告诉我们当前仓库的状态。
➜ Code git:(master) git status
On branch master
nothing to commit, working tree clean
上面的内容告诉我们,当前仓库没有改动,因此无需提交新的内容。
当我们在仓库中修改文件后,但是还没有提交时:
➜ Code git:(master) ✗ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test.txt
no changes added to commit (use "git add" and/or "git commit -a")
这段提示告诉我们仓库中的test.txt文件被修改了,但目前还没有提交。
git diff命令
git diff命令可以告诉我们仓库中的文件修改了什么。
diff --git a/test.txt b/test.txt
index 4e721ad..7a3b7a6 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
this is a file.
Then I will test another git command.
+Good Luck!
(END)
使用git diff命令后,控制台回显出上面的信息。它告诉我们,test.txt文件中增加了一行"Good Luck!"
当我们把改动提交后:
再次使用git diff命令,此时控制台回显:
(END)
说明没有修改后未提交的内容了。