查看仓库状态,及修改内容
修改readme.txt 文件,改成内容给如下
git is a distributed version control system
修改readme.txt 文件,改成内容给如下
git is a distributed version control system
git is free software
运行git status命令,查看结果如下:
$ 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.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
git status 命令可以让我们了解仓库当前状态,上面的命令告诉我们,readme.txt被修改过,但是还没被提交修改的内容。
这个时候我们想要看修改的具体内容,就可以使用git diff命令
$git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
Git is free software.
git diff 就是查看difference ,显示格式正是Unix通用的diff格式,接下来从上面的命令输出看到,我们在第一行添加了一个“distributed”单词。知道了对readme.txt作了什么修改后,再把它提交到仓库就放心多了,提交修改和提交新文件是一样的两步,第一步是git add:
$git add 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 告诉我们,将要被提交的的修改包括readm.txt,下一步就是提交了.
$git commit -m "add distributed"(提交说明)
[master ea34578] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
提交后,我们再用git status命令看看仓库的当前状态:
$ git status
# On branch master
nothing to commit (working directory clean)
Git告诉我们当前没有需要提交的修改,而且,工作目录是干净(working directory clean)的