时光机穿梭
上文写了一个readme文件,现在修改它,再输入git status
:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
git status
命令可以让我们时刻掌握仓库当前的状态,上面的命令输出告诉我们,readme.txt被修改过了,但还没有准备提交的修改。
虽然Git告诉我们readme.txt被修改了,但如果能看看具体修改了什么内容,自然是很好的。有时候已经记不清上次怎么修改的readme.txt,所以,需要用git diff
这个命令看看:
$ git diff
diff --git a/readme.txt b/readme.txt
index e29912c..ca0fed9 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1,2 @@
-This is for git learning.
\ No newline at end of file
+This is for git learning,hhh.
+Git is free software.
\ No newline at end of file
这里看到,我们添加了一句话。
知道了对readme.txt作了什么修改后,再把它提交到仓库就放心多了。
在执行第二步git commit之前,我们再运行git status
看看当前仓库的状态:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
git status
告诉我们,将要被提交的修改包括readme.txt,下一步,就可以放心地提交了:
$ git commit -m "add distributed"
[master e475afc] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
提交后,再用git status命令:
$ git commit -m "add distributed"
[master e475afc] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)