您的位置:首页 > 其它

Git-02_版本回退

2014-11-26 23:36 190 查看


删除仓库

说明

删除掉.git目录即可删除repository

操作

$ cd e:

$ cd git_repository/

$ ls -a

. .. .git hello.txt

$ rm -rf .git hello.txt

$ ls -a

. ..

准备工作

初始化仓库

$ git init

Initialized empty Git repository in e:/git_repository/.git/

创建文件

$ touch hello.txt

提交文件

$ git add hello.txt

$ git commit hello.txt -m "create hello.txt"

[master (root-commit) 3ec0011] create hello.txt

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 hello.txt

修改文件

添加数据

数据

the first line: I like git!

$ echo 'the first line: I like git!' >> hello.txt

$ cat hello.txt

the first line: I like git!

$ git add hello.txt

$ git commit hello.txt -m "append a line: I like git"

$ git status

On branch master

nothing to commit, working directory clean

添加数据

数据

the second line: Git is powerful~

$ echo 'the second line: Git is powerful~' >> hello.txt

$ cat hello.txt

the first line: I like git!

the second line: Git is powerful~

$ git status

$ git add hello.txt

$ git commit hello.txt -m "append a line: Git is powerful"

查看版本

命令

$ git log

$ git log --pretty=oneline

$ git log --pretty=oneline --abbrev-commit

示例

$ git log

commit f69a305be8d203da324992b88e8de00127c53581

Author: wuqinfei <wuqinfei@qq.com>

Date: Mon Nov 10 19:42:21 2014 +0800

append a line: Git is powerful

commit 49cc630ed86f6f24c73df113c42a4f0763d691f6

Author: wuqinfei <wuqinfei@qq.com>

Date: Mon Nov 10 19:35:10 2014 +0800

append a line: I like git

commit 3ec0011e5c26da1250abe1e6c551add42343eaa2

Author: wuqinfei <wuqinfei@qq.com>

Date: Mon Nov 10 19:31:39 2014 +0800

create hello.txt

$ git log --pretty=oneline

f69a305be8d203da324992b88e8de00127c53581 append a line: Git is powerful

49cc630ed86f6f24c73df113c42a4f0763d691f6 append a line: I like git

3ec0011e5c26da1250abe1e6c551add42343eaa2 create hello.txt

说明

每提交一次就创建一个快照, 这个快照在Git中被称为commit

commit f69a...581

commit id, 版本号

版本号是由 SHA1 计算出来的一个非常大的十六进制数字

回退版本

命令

$ git reset --hard HEAD^

版本

HEAD

表示当前版本, 0

HEAD^

表示上一个版本, -1

HEAD^^

表示上上一个版本, -2

HEAD~100

表示上100个版本, -100

示例

回退到上一版本

$ git log --pretty=oneline

f69a305be8d203da324992b88e8de00127c53581 append a line: Git is powerful

49cc630ed86f6f24c73df113c42a4f0763d691f6 append a line: I like git

3ec0011e5c26da1250abe1e6c551add42343eaa2 create hello.txt

$ git reset --hard HEAD^

HEAD is now at 49cc630 append a line: I like git

$ git log --pretty=oneline

49cc630ed86f6f24c73df113c42a4f0763d691f6 append a line: I like git

3ec0011e5c26da1250abe1e6c551add42343eaa2 create hello.txt

后悔了,想回到最新版

$ git reset --hard f69a305be8d203da3

HEAD is now at f69a305 append a line: Git is powerful

$ git log --pretty=oneline

f69a305be8d203da324992b88e8de00127c53581 append a line: Git is powerful

49cc630ed86f6f24c73df113c42a4f0763d691f6 append a line: I like git

3ec0011e5c26da1250abe1e6c551add42343eaa2 create hello.txt

历史操作

说明

记录你的每一次命令

示例

$ git reflog

f69a305 HEAD@{0}: reset: moving to f69a305be8d203da3

49cc630 HEAD@{1}: reset: moving to HEAD^

f69a305 HEAD@{2}: commit: append a line: Git is powerful

49cc630 HEAD@{3}: commit: append a line: I like git

3ec0011 HEAD@{4}: commit (initial): create hello.txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: