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")

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

转载于:https://www.cnblogs.com/LvLoveYuForever/p/5492449.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值