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 <[email protected]>
Date: Sat Aug 13 15:33:04 2016 +0800
second submit
commit 07182c2051fc1e76ad48d329f953e0c33a932b3b
Author: chenkang1990 <[email protected]>
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 <[email protected]>
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

你可能感兴趣的:(git)