Blame

3de8bd Qwas 2024-10-14 07:35:51 1
# git
09079a Qwas 2024-10-14 07:35:02 2
3
内容来自 *Git:Mastering Version Control*
4
5
《Git:Mastering Version Control》 Ferdinando Santacroce Aske Olsson Rasmus Voss Jakub Narębski
6
7
## git config
8
9
```sh
10
git config --list
11
```
12
13
```sh
14
git config user.name "Aske Olsson"
15
git config user.email "askeolsson@example.com"
16
```
17
18
### 指定编辑器
19
20
```sh
21
git config --global core.editor vim
22
```
23
24
```sh
25
git config --global core.editor code
26
```
27
28
### 一些有用得 alias:
29
30
```sh
31
git config <level> alias.<alias name> '<your sequence of git commands>'
32
```
33
34
```sh
35
git config --global alias.unstage 'reset HEAD --'
36
git config --global alias.undo 'reset --soft HEAD~1'
37
git config --global alias.cm 'commit -m'
38
git config --global alias.co checkout
39
git config --global alias.br branch
40
git config --global alias.ci commit
41
git config --global alias.st status
42
git config --global alias.tree 'log --graph --decorate --pretty=oneline --abbrev-commit'
43
git config --global alias.graph "log --all --graph --pretty=format:'%Cred%h%Creset -%C (yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset'"
44
```
45
46
### 自定义设置
47
48
这些设置对 Git 本身没有影响,但是对脚本或构建工具很有用
49
50
```sh
51
git config my.own.config "Whatever I need"
52
```
53
54
删除配置条目
55
56
```sh
57
git config --unset my.own.config
58
```
59
60
## checkout
61
62
```sh
63
git checkout
64
```
65
66
checkout 上一次分支
67
68
## diff
69
70
```sh
71
git diff main..dev
72
```
73
74
`git diff <source branch> .. <target branch>`
75
76
对比分支差异
77
78
## log
79
80
```sh
81
git log main..dev
82
```
83
84
对比分支 commit message
85
86
## remote
87
88
```sh
89
git remote show origin
90
```
91
92
```sh
93
git remote add upstream https://github.com/<original-owner>/<original-repository>.git
94
```
95
96
```sh
97
git remote add origin <remote-repository-url>
98
git remote add upstream https://github.com/octocat/Spoon-Knife.git
99
```
100
101
## autocorrect
102
103
拼写自动校正
104
105
```sh
106
git config --global help.autocorrect 10
107
```
108
109
> 中止自动校正 `Ctrl + C`
110
111
## blame
112
113
git blame
114
115
## archive
116
117
```sh
118
git archive HEAD --format=zip --output=../headbck.zip
119
```
120
121
## bundle
122
123
```sh
124
git bundle create ../repo.bundle master
125
```
126
127
## git worktree