Compare commits

...

5 Commits

Author SHA1 Message Date
4bdf9b82bc update 2.5 notes 2024-08-16 15:40:37 +02:00
dd95d391fb Merge commit 'c4dea21' 2024-08-16 10:51:02 +02:00
c4dea21d20 commit in detached mode 2024-08-16 10:42:17 +02:00
c4332b7c93 1040 test 2024-08-16 10:40:45 +02:00
90fcb4ac61 add 2.5 notes 2024-08-16 10:39:20 +02:00
3 changed files with 43 additions and 0 deletions

42
notes/2.5_git_checkout.md Normal file
View File

@ -0,0 +1,42 @@
## 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是想暂存区中覆盖工作区的内容
第二种用法就是切换分支
第三种用法是新建分支

View File

@ -1 +1,2 @@
welcome
1039

View File