Git第一天内容的实践

工作区修改:新建b.txt,输入文字为test1,删除了a.txt
执行git add b.txt a.txt

$ git diff      #无显示
$ git diff HEAD -- b.txt #工作区和分支的对比
diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..ad1a4f3
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+text1 
$ $ git diff --cached b.txt   #暂存区和分支对比
diff --git a/b.txt b/b.txt
new file mode 100644
index 0000000..ad1a4f3
--- /dev/null
+++ b/b.txt
@@ -0,0 +1 @@
+text1
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    a.txt
    new file:   b.txt
    更改b保存之后,git checkout -- b.txt
    更改消失,b恢复原样,checkout命令清除了工作区
    再次更改b保存,git diff
$ git diff
diff --git a/b.txt b/b.txt
index ad1a4f3..be69c1f 100644
--- a/b.txt
+++ b/b.txt
@@ -1 +1,2 @@
 text1
+text2
\ No newline at end of file
接下来git add将b添加到暂存区,checkout之后再次git diff无返回内容,工作区中内容和暂存区中一样,用暂存区和分支对比发现新增内容(回到最近一次commit或者add时的状态,那么当再次修改之后,执行checkout就会回到上次add时的内容。)
在commit之前用git reset HEAD filename   HEAD表示当前版本,把暂存区的修改撤销掉,再用git checkout -- filename 消除工作区
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值