[git 学习篇] 修改文件

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013743858312764dca7ad6d0754f76aa562e3789478044000

第一步,我们将git 里面的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")

上面一大堆是告诉我们,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”单词。

第四步,提交修改后的文件,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告诉我们,将要被提交的修改包括readme.txt,下一步,就可以放心地提交了:

第六步,放心提交 

$ git commit -m "add distributed"
[master ea34578] add distributed
 1 file changed, 1 insertion(+), 1 deletion(-)

第七步,再次查看git状态

$ git status
# On branch master
nothing to commit (working directory clean)
Git告诉我们当前没有需要提交的修改,而且,工作目录是干净(working directory clean)的。

 

posted @ 2017-06-23 09:36  liuzhipenglove  阅读(484)  评论(0编辑  收藏  举报