查看修改状态

接着上次git用法(一)创建版本库,我们已经成功地添加并提交了一个README.md文件,现在,我们继续修改README.md文件,改成如下内容:

1
Git is very good

现在,运行git status命令看看结果:

1
2
3
4
5
6
7
8
9
$ 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: README.md
no changes added to commit (use "git add" and/or "git commit -a")

Changes not staged for告诉我们README.md被修改了,但还没有提交修改,而且修改了什么内容也不知道,这是如果需要查看修改了什么内容的话可以通过git diff命令看看:

1
2
3
4
5
6
7
8
9
10
$ git diff README.md
diff --git a/README.md b/README.md
index ab0fd0f..b0ba4df 100644
--- a/README.md
+++ b/README.md
@@ -1 +1 @@
-Git is good
\ No newline at end of file
+Git is very good
\ No newline at end of file

可以从上面的命令输出可以看出,对比如下

1
2
3
4
-Git is good
\ No newline at end of file
+Git is very good
\ No newline at end of file

看到内容的改变增加了一个单词 “good”,知道修改了什么后,就可以提交到版本库了,还是两步走:
一,git add

1
$ git add README.md

同样没有任何输出。在执行第二步git commit之前,我们再运行git status看看当前仓库的状态:

1
2
3
4
5
6
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: README.md

可以看出修改已经提交了

二, git commit
最终可以提交的版本库了

1
2
3
$ git commit -m "add good word"
[master 1d0f9dd] add good word
1 file changed, 1 insertion(+), 1 deletion(-)

提交后,我们再用git status命令看看仓库的当前状态:

1
2
3
$ git status
On branch master
nothing to commit, working directory clean

热评文章