1
0
forked from iicd/git-learner
git-learner/notes/2.5_git_checkout.md
2024-08-16 15:40:37 +02:00

43 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 2.5 Git Checkout
### 2.5.1 HEAD reset = checkout
查看当前的branch
```bash
git branch -v
```
checkout到commit的父亲使得head指针指向父提交而不是branch
```bash
git checkout <commit>^
```
在detach模式下addcommitHEAD都是指向最新的提交
之后再checkout到原来的分支detach模式下的操作记录都会丢失
### 2.5.2 git merge
```bash
git merge <commit>
```
<commit>提交合并到当前分支,这样做就可以把detach模式下的提交merge到当前分支上
合并以后的提交将有两个父提交
### 2.5.3 git checkout
```bash
用法一: git checkout [-q] [<commit>] [--] <paths>...
用法二: git checkout [<branch>]
用法三: git checkout [-m] [[-b|--orphan] <new_branch>] [<start_point>]
```
第一种用法的`<commit>`是可选项如果省略则相当于从暂存区index进行检出。reset的默认值是 HEAD而checkout的默认值是暂存区。
reset的目的是用HEAD重置暂存区checkout是想暂存区中覆盖工作区的内容
第二种用法就是切换分支
第三种用法是新建分支