Git 中文手册 | Git Referer
1
2
3
4
5
|
撤销 add
`git reset HEAD filename`
撤销 commit
`git reset --soft HEAD^`
|
1
2
3
4
|
/etc/gitconfig 系统
~/.gitconfig 或 ~/.config/git/config 只针对当前用户 可传参 ‘global’让Git读写此文件
.git/config 针对当前仓库的配置文件
上面三个,越下面级别越高
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
- 用户信息
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
查看配置信息:'git config --list'/'git config -l'
- 设置/删除代理
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
- 默认编辑器是vi,更改为vim
git config --global core.editor "vim"
- 设置终端带颜色
git config --global color.ui true
|
1
2
3
|
git help <verb>
git <verb> --help
man git-<verb>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
1.git init
初始化git仓库
2.git status
查看git仓库的状态
3.git add
缓存添加文件(夹)到git仓库
4.git rm -cached
移除添加的缓存
5.git commit -m 'something'
commit 代表提交
-m 表示提交附属信息,对此次提交的描述
6.git log
查看提交日志
7.git branch
查看当前分支 git branch
新建分支a git branch a
新建a分支并切换到a分支 git checkout -b a
删除无用的a分支 git branch -d a
若a还没合并到main,则上一条会失败,-D可强制删除 git branch -D
8.git merge
要先切换到main分支,然后git merge a就可将a合并到main分支
11.git tag
添加标签,方便切换和查找
查看标签 git tag
切换 git checkout v1.0
|
1
2
3
4
|
生成rsa秘钥 ssh-keygen -t rsa
\ 生成的文件在 ~/.ssh 目录下,将pub中的内容复制到GitHub上。
\ 设置 >> SSh >> new SSH key
\ 输入ssh -T git@github.com 进行测试是否添加成功
|
1
2
|
git push origin main 本地代码推到远程分支
git pull origin main 远程代码拉到本地
|
一般 push 之前会先 pull
1
2
3
4
5
|
git diff <$id1> <$id2> 比较两次提交之间的差异
git diff .. 在两个分支之间比较
git diff --staged 比较暂存区和版本库差异
|
可以撤销还没 add 进暂存区的文件
代码还未 commit 之前暂时切换到另外的分支
1
2
3
4
5
6
7
8
9
|
git stash list 暂存区记录
git stash apply 还原
git stash drop 删除这次 stash 记录
git stash pop 还原并删除
git stash clear 清空
|
1
2
3
4
5
6
7
8
9
|
git checkout master
git merge featureA
等价于
git checkout master
git rebase featureA rebase 会按时序合并
|
查看本地分支列表
查看远程分支列表
删除本地分支
1
2
|
git branch -d develop
git branch -D develop (强制删除)
|
删除远程分支
1
|
git push origin :develop
|
如果远程分支有个 develop ,而本地没有,你想把远程的 develop 分支迁到本地:
1
|
git checkout develop origin/develop
|
同样的把远程分支迁到本地顺便切换到该分支:
1
|
git checkout -b develop origin/develop
|