git 版本前进与后退

查看日志:

$  git log
commit 4dee986564735b586cf766e70b81f127aa53ccac (HEAD -> master)
Author: wanzew <wanzew>
Date:   Tue Apr 2 09:27:52 2019 +0800

    second commit, added a line in the file

commit a7673da2d0eb9950dacd102d811504a921d450ae
Author: wanzew <wanzew>
Date:   Tue Apr 2 09:18:48 2019 +0800

    first commit

简洁显示方式:

git log --pretty=oneline
git log --oneline
git reflog

使用 git reflog 命令

显示的内容中:HEAD@{步数}, 其中步数表示想要回到该版本需要的步数。

基于索引值前进后退版本:

git reset --hard [索引值]

reset 命令的三个参数对比:

--soft参数:

Does not touch the index file or the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

只会在本地库移动指针,不会重置工作区和暂存区。

--mixed

Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.

在本地库移动HEAD指针,会重置暂存区。

--hard参数:

Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.

在本地库移动HEAD指针,重置暂存区,重置工作区。

猜你喜欢

转载自blog.csdn.net/wanzew/article/details/88963543
今日推荐