git使用指南

1.配置

1.1. 基本配置

[user]
    email = zhj88523@gmail.com # 用户邮箱
    name = snowwalf # 用户名
[core]
    editor = vim # git信息编辑器
[diff]
    tool = vimdiff
[color]
    branch = auto
    diff = auto
    interactive = auto
    status = auto

1.2. 常用指令别名

[alias]
    br = branch
    st = status
    ci = comiit
    co = checkout
    rb = rebase
    lg = log --graph --all -n 50 --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative # commit信息树形图
    ca = commit --amend
    cs = commit -s

1.3. commit信息模板

[commit]
    template = <path_to_template>

git_commit_template.txt

1.4. 网络访问

1.4.1. url协议

ssh协议

# Use git and git+ssh instead of https
[url "git://github.com/"]
  insteadOf = https://github.com/
[url "git@github.com:"]
  pushInsteadOf = "git://github.com/"
[url "git@github.com:"]
  pushInsteadOf = "https://github.com/"

https协议

# Use https instead of git and git+ssh
[url "https://github.com/"]
  insteadOf = git://github.com/
[url "https://github.com/"]
  insteadOf = git@github.com:

1.4.2. 代理

# socks5 proxy
[http]
        proxy = socks5://127.0.0.1:1086
[https]
        proxy = socks5://127.0.0.1:1086

2. 常用指令

命令 说明
git diff branch1..branch2 /path/folder 比较指定目录的两个branch差异
git checkout branch1 -- /path/folder 从某branch上cherry-pick出指定目录的差异文件到当前branch
Table of Contents