首页 > git > git文件修改、提交

git文件修改、提交

来源:原创 作者:thomas 分类:git 阅读:686 日期:2014-06-03

修改readme.txt文件,改成如下内容:

Git is a distributed version control system.

Git is free software.

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

$ git status

# On branch master

# Changed but not updated:

#   (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 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告诉我们,将要被提交的修改包括readme.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告诉我们当前没有需要提交的修改。

十日谈技术博客

 

热门文章 更多>

微信扫一扫,关注技术十日谈