git-learner/notes/2.4-git_reset.md

34 lines
694 B
Markdown
Raw Permalink Normal View History

2024-08-15 22:28:24 +02:00
### 2.4.1 reset
`HEAD^`代表版本库中的上一次提交
2024-08-16 10:17:30 +02:00
### 2.4.2 reflog
查看前五次提交的内容
```
tail -5 .git/logs/refs/heads/master
```
查看最后五次提交内容
```text
git reflog show master | head -5
```
得到一个更容易记录的号码`branch@{#}`,来用`git reset --<way> branch@{#}`来记录
### 2.4.3
`git reset [-- filename] `用HEAD重置暂存区,加上filename之后只重置单个文件
2024-08-15 22:28:24 +02:00
1. HEAD指向的branch更换成指定的commit ID
2. 暂存区中的内容替换成HEAD指向的branch的目录树
3. 把工作区替换成暂存区中的目录树
2024-08-16 10:17:30 +02:00
2024-08-15 22:28:24 +02:00
`git reset --hard commit` 1 2 3
`git reset --soft commit` 1
`git reset --mixed commit` 1 2
2024-08-15 22:19:41 +02:00