配置
查看配置
1 2 3
| git config --global --list
git config --global -l
|
修改配置方法
命令行修改
使用命令行添加或修改配置:
PS: 有3种级别的配置
1 2 3 4 5 6
| git config --system core.autocrlf xxx
git config --global user.name xxx
git config --local remote.origin.url xxx
|
使用命令行删除配置:
1
| git config --global --unset alias.别名
|
配置文件修改
使用如下命令可以快速打开config文件
1
| git config --global --edit
|
也可以手动打开文件,config文件内容类似下文,修改后保存即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| [core] editor = \"C:\\coding\\Sublime Text 3\\sublime_text.exe\" -w autocrlf = true [user] name = username email = example@example [http] version = HTTP/1.1 [alias] st = status br = branch co = checkout ci = commit -m l = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit # pr = pull --rebase origin master # pru = pull --rebase upstream master # r = remote -v # rau = remote add upstream # pf = push origin master --force [i18n] commitencoding = utf-8 logoutputencoding = utf-8
|
个人身份
1 2
| git config --global user.name "username" git config --global user.email "example@example"
|
换行符
Windows
1
| git config --global core.autocrlf true
|
Linux or Max
1
| git config --global core.autocrlf input
|
only Windows
1
| git config --global core.autocrlf false
|
中文编码
1 2 3 4 5 6
| git config --global gui.encoding utf-8 git config --global i18n.commitencoding utf-8 git config --global i18n.logoutputencoding utf-8
git config --global core.quotepath false
|
与服务器认证
1 2 3 4 5 6 7
| git config --global credential.helper store
git config http.sslverify false
ssh-keygen -t rsa -C example@example
|
常用基本指令
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
| git init git clone
git add git rm git mv
git diff git status
git commit
git log
git push
git branch git checkout git branch -d git pull
git merge git rebase
git reset git checkout
|
别名设置
添加git的alias
1
| git config --global alias.别名 "命令全称"
|
个人配置
1 2 3 4 5
| git config --global alias.st "status" git config --global alias.br "branch" git config --global alias.co "checkout" git config --global alias.ci "commit" git config --global alias.l "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
|
config文件相关内容如下
1 2 3 4 5 6
| [alias] st = status br = branch co = checkout ci = commit -m l = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
|
修改commit
修改最后一次提交 commit 的信息
1 2 3 4 5 6 7 8
| git commit --amend --message="modify message" --author="username <example@example>"
git commit --amend --message="modify message"
git commit --amend --author="username <example@example>"
|
修改历史提交 commit 的信息
操作步骤:
git rebase -i
列出 commit 列表
- 找到需要修改的 commit 记录,把
pick
修改为 edit
或 e
,:wq
保存退出
- 修改 commit 的具体信息
git commit --amend
,保存并继续下一条git rebase --continue
,直到全部完成
- 中间也可跳过或退出
git rebase (--skip | --abort)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| git rebase -i <commit id>
git rebase -i HEAD~3
git rebase -i
git commit --amend --message="modify message" --author="username <example@example>" git rebase --continue
git rebase --skip git rebase --abort
|
修改完成后,强制推送到远程服务器