您的位置:首页 > 其它

git版本回退

2015-12-16 15:46 337 查看
1. 修改readme.txt的内容,并提交至版本库

readme.txt

git is a version control system.
git is free software.
$ 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 add readme.txt
$ git commit -m "free software"
[master 85e468e] free software
1 file changed, 2 insertions(+), 1 deletion(-)
git status 查看当前状态

2. 再次修改readme.txt,并提交至版本库

readme.txt

git is a version control system.
git is free software under the GPL.
$ 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 add readme.txt
$ git commit -m "append GPL"
[master 75fa7b7] append GPL
1 file changed, 1 insertion(+), 1 deletion(-)


3. 查看提交历史 git log

$ git log
commit 75fa7b7807f45b9ab8847a407e4b03562660da8e
Author: morris131 <morris131@163.com>
Date:   Wed Dec 16 15:31:55 2015 +0800
append GPL
commit 85e468ecae088f05d21dc7ce9ccb6ef41c1c6f8c
Author: morris131 <morris131@163.com>
Date:   Wed Dec 16 15:29:06 2015 +0800
free software
commit a2de034c5e9a9fda86d7ed7005265493cd2a054b
Author: morris131 <morris131@163.com>
Date:   Wed Dec 16 13:44:53 2015 +0800
git init
一行显示历史提交记录

$ git log --pretty=oneline
75fa7b7807f45b9ab8847a407e4b03562660da8e append GPL
85e468ecae088f05d21dc7ce9ccb6ef41c1c6f8c free software
a2de034c5e9a9fda86d7ed7005265493cd2a054b git init


4. 回退到上一个版本(free software)

$ git reset --hard HEAD^
HEAD is now at 85e468e free software
readme.txt内容如下:

git is a version control system.
git is free software.


5. 再回退到上一个版本(git init)

$ git reset --hard HEAD^
HEAD is now at a2de034 git init
readme.txt内容如下:

git is a version control system.


6. 回退到append GPL版本

$ git reflog
a2de034 HEAD@{0}: reset: moving to HEAD^
85e468e HEAD@{1}: reset: moving to HEAD^
75fa7b7 HEAD@{2}: commit: append GPL
85e468e HEAD@{3}: commit: free software
a2de034 HEAD@{4}: commit (initial): git init
git reflog 记录每次操作的命令,找到append GPL的版本号75fa7b7

$ git reset --hard 75fa7b7
HEAD is now at 75fa7b7 append GPL
readme.txt内容如下:

git is a version control system.
git is free software under the GPL.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: