reset 命令就是穿梭到某个历史版本,有多种选项,以下讨论常见的三种选项,其他git新增的选项不讨论
场景描述:有两个历史版本,一个是a,一个是b,现在我处于b,并且我还有一些文件是added状态的,
也就是还没有commit提交分支;另外还有一些文件是untracked状态的,还没有添加到git里面。
我现在要从b版本和手头上这些正在进行的工作(也就是added和untracked的东西)穿梭回a版本
git reset [<mode>] [<commit>]
hard | mixed | soft | |
---|---|---|---|
committed | 直接没了 | 变成untracked | 变成added |
added | 直接没了 | 变成untracked | 还是added |
untracked | 还是untracked | 还是untracked | 还是untracked |
modified | 还是untracked | 还是untracked | 还是untracked |
modified-added | 直接没了 | 变成modified | 还是modified-added |
可以看到:
- 对于 untracked 的内容,一直都是不变的,因为这部分都还没有 add 到 git 里面,它跟 git 没有半毛钱关系
--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.
If -N is specified, removed paths are marked as intent-to-add (see git-add(1)).
--hard
Resets the index and working tree. Any changes to tracked files in the working tree since <commit> are discarded.
网友评论