git 修改文件内容
在安装Git和创建版本库的时候,我们已经成功地添加并提交了一个readme.txt文件,现在,是时候继续工作了,于是,我们继续修改readme.txt文件,改成如下内容
[root@node1 git]# cat readme.txt
Git is a distributed version control system.
Git is free software
现在,运行git status
命令看看结果
[root@node1 git]# 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 查看修改内容
[root@node1 git]# git diff readme.txt diff --git a/git/readme.txt b/git/readme.txt index 46d49bf..87aec63 100644 --- a/git/readme.txt +++ b/git/readme.txt @@ -1,2 +1,2 @@ -Git is a version control system. -Git is free software. +Git is a distributed version control system. +Git is free software
可以从上面的命令输出看到,我们在第一行添加了一个“distributed”单词。
提交修改和提交新文件是一样的两步,第一步是git add
[root@node1 git]# git add readme.txt
在执行第二步git commit
之前,我们再运行git status
看看当前仓库的状态
[root@node1 git]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: readme.txt #
git status
告诉我们,将要被提交的修改包括readme.txt,下一步,就可以放心地提交了
[root@node1 git]# git commit -m "add distributed" [master df9bbb2] add distributed 1 file changed, 2 insertions(+), 2 deletions(-)
交后,我们再用git status
命令看看仓库的当前状态
[root@node1 git]# git status
# On branch master
nothing to commit, working directory clean
Git告诉我们当前没有需要提交的修改,而且,工作目录是干净(working directory clean)的