码迷,mamicode.com
首页 > 其他好文 > 详细

Git 提交修改内容和查看被修改的内容

时间:2016-05-14 15:29:26      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

我们将仓库里的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两步:

LV@LV-PC MINGW32 /c/gitRespository (master)
$ git add readme.txt            //添加修改的文件

LV@LV-PC 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


LV@LV-PC 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(-)

LV@LV-PC MINGW32 /c/gitRespository (master)
$ git status              //当前仓库状态:没有需要提交的修改,工作目录是干净的
On branch master
nothing to commit, working directory clean

Git 提交修改内容和查看被修改的内容

标签:

原文地址:http://www.cnblogs.com/LvLoveYuForever/p/5492449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!