跟着廖雪峰的git教程学习(2)时光机穿梭

我们已经成功地添加并提交了一个hello.html文件,现在,是时候继续工作了,于是,我们继续修改hello文件,改成如下内容:

<!DOCTYPE html>
<html>
<head>
	<title>hello</title>
</head>
<body>
   <p>it's a text for git</p>
</body>
</html>

现在,运行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:   hello.html


no changes added to commit (use "git add" and/or "git commit -a")

git status命令可以让我们时刻掌握仓库当前的状态,上面的命令告诉我们,hello.html被修改过了,但还没有准备提交的修改。

虽然Git告诉我们hello.htmlt被修改了,但如果能看看具体修改了什么内容,自然是很好的。比如你休假两周从国外回来,第一天上班时,已经记不清上次怎么修改的hello.html,所以,需要用git diff这个命令看看:

$ git diff
diff --git a/hello.html b/hello.html
index 8e56559..c496c3e 100644
--- a/hello.html
+++ b/hello.html
@@ -1,9 +1,9 @@
-<<!DOCTYPE html>
+<!DOCTYPE html>
 <html>
 <head>
        <title>hello</title>
 </head>
 <body>
-   llllll
+   <p>it's a text for git</p>
 </body>
 </html>
\ No newline at end of file

git diff顾名思义就是查看difference,显示的格式正是Unix通用的diff格式,可以从上面的命令输出看到,我们把body里面的内容改为it's a text for git 还有html上面少了个括号

知道了对hello.htmlt作了什么修改后,再把它提交到仓库就放心多了,提交修改和提交新文件是一样的两步,第一步是git add

$ git add hello.html

同样没有任何输出。在执行第二步git commit之前,我们再运行git status看看当前仓库的状态:

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)


        modified:   hello.html


git status告诉我们,将要被提交的修改包括hello.html,下一步,就可以放心地提交了:

$ git commit -m "add distributed"(这里add distributed 写错了  本来应该是对你修改的内容描述 当时看廖雪峰大大写到这 一下子没明白后来才看明白 所以这应该是改为add p element)
[master e310b3c] add distributed
 1 file changed, 2 insertions(+), 2 deletions(-)

提交后,我们再用git status命令看看仓库的当前状态:

$ git status
# On branch master
nothing to commit (working directory clean)

Git告诉我们当前没有需要提交的修改,而且,工作目录是干净(working directory clean)的。

小结一下:

  • 要随时掌握工作区的状态,使用git status命令。

  • 如果git status告诉你有文件被修改过,用git diff可以查看修改内容。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值