我们将仓库里的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虽然告诉我们readme.txt被修改了,但是如果能看到修改了什么内容就是最好的了,好比你忘记了上次怎么修改的readme.txt,
这时候你就要用 git diff这个命令看看:
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index 58998b5..9c3f69a 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.
\ No newline at end of file
git diff 顾名思义就是查看difference,显示格式正是Unix通用的diff格式,可以从上面的输出信息看出,第一行添加了一个"distributed"单词。
知道了对readme.txt作了什么修改后,再把它提交到仓库就放心多了,提交修改和提交新文件是一样的,分add和commit两步:
[email protected] MINGW32 /c/gitRespository (master)
$ git add readme.txt //添加修改的文件
[email protected] MINGW32 /c/gitRespository (master)
$ git status //当前仓库的状态:将要被提交的修改包括readme.txt
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: readme.txt
[email protected] MINGW32 /c/gitRespository (master)
$ git commit -m "modify the readme.txt commit" //提交
[master 4b1d71b] modify the readme.txt commit
1 file changed, 1 insertion(+), 1 deletion(-)
[email protected] MINGW32 /c/gitRespository (master)
$ git status //当前仓库状态:没有需要提交的修改,工作目录是干净的
On branch master
nothing to commit, working directory clean