03.git版本修改提交、回退

修改提交

1. 继续修改firstCode.txt文件;内容如下:1.fisrt  2.second  3.three
2. 

$ git status 查看当前版本库状态,显示有文件修改,等待add
On branch master
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout – …” to discard changes in working directory)
modified: firstCode.txt
no changes added to commit (use “git add” and/or “git commit -a”)

3. git显示文件已经被修改;
4. 

$ git diff firstCode.txt 显示不同
diff –git a/firstCode.txt b/firstCode.txt
index c2a9a62..57c8239 100644
— a/firstCode.txt
+++ b/firstCode.txt
@@ -1,2 +1,3 @@
1.fisrt
-2.second
\ No newline at end of file
+2.second
+3.three
\ No newline at end of file

5. 

$ git add firstCode.txt

6. 

$ git status
On branch master
Changes to be committed:
(use “git reset HEAD …” to unstage)
modified: firstCode.txt

7. 

git commit -m “second submit”
[master 9b1a1a8] second submit
1 file changed, 2 insertions(+), 1 deletion(-)

8. 

$ git status
On branch master
nothing to commit, working tree clean

回退版本

1. 

$ git log 显示版本提交历史信息
commit 9b1a1a8a1a5b232caaad3edb8272b6acb619426e
Author: chenkang1990 <623580460@qq.com>
Date: Sat Aug 13 15:33:04 2016 +0800
second submit
commit 07182c2051fc1e76ad48d329f953e0c33a932b3b
Author: chenkang1990 <623580460@qq.com>
Date: Sat Aug 13 15:22:55 2016 +0800

2. 

$ git reset –hard HEAD^
HEAD is now at 07182c2 create file

3. 用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写成HEAD~100。
4. 回退到上一个版本成功;
5. 

$ git log
commit 07182c2051fc1e76ad48d329f953e0c33a932b3b
Author: chenkang1990 <623580460@qq.com>
Date: Sat Aug 13 15:22:55 2016 +0800
create file

6. 只有上一个版本以前的信息了;
7. 

$ git reflog
07182c2 HEAD@{0}: reset: moving to HEAD^
9b1a1a8 HEAD@{1}: commit: second submit
07182c2 HEAD@{2}: commit (initial): create file

8. 看到所有版本信息。可以回到现在
9. 

$ git reset –hard 9b1a1a8
HEAD is now at 9b1a1a8 second submit

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值