前言

我在工作中应用 vscode 作为开发编辑器,本地装置了 TortoiseGit 、git bash、Conemu 来使得命令行操作有所缩小,然而必要的命令还是必须的。为了进步操作的效率与应用体验,还做了自定义配置。

在这里记录一下我罕用的 Git 命令清单,不便查阅。

命令清单

初始化

# 配置用户名git config --global user.name "本人的名字"# 配置邮箱git config --global user.email "本人的邮箱"# 生成设施公钥ssh-keygen -t rsa || ssh-keygen# 测试 github 连贯状态ssh -T git@github.com# 拷贝我的项目与历史记录git clone [url]

配置

# 显示以后的Git配置git config --list# 编辑Git配置文件git config -e [--global]

查看信息

# 查看提交日志,图形化显示合并关系 (自定义简化命令)git lgh# 显示整个本地仓库的最近提交,包含所有分支git reflog# 显示工作区有变更的文件git status => git st# 查看某次 commmit 的提交信息git show [commitID]# 显示某次提交时,某个文件的内容$ git show [commitID]:[filename]# 显示两次提交之间的差别$ git diff [first-commitID] [second-commitID]

撤销

# 重置以后分支的HEAD为指定commitID,同时重置暂存区和工作区,与指定commit统一git reset --hard [commitID]# 勾销 rebasegit rebase --abort

代码提交

=> 后为自定义的简化命令
# 拉取远端最新代码(本地没有批改)git pull --rebase => git pr# 拉取远端最新代码(本地有批改)git pull --rebase --autostash => git prs# 增加指定文件到暂存区git add [file1] [file2] ...# 增加当前目录的所有文件到暂存区git add .# 提交 log 正文git commit -m "commit log"# 推送到远端git push

分支

# 列出所有本地分支git branch => git br# 列出所有近程分支git branch -r# 列出所有本地分支和近程分支git branch -a# 新建一个分支,但仍然停留在以后分支git branch [branch-name]# 新建一个分支,并切换到该分支git checkout -b [branch]# 合并指定分支到以后分支git merge [branch]# 删除分支git branch -d [branch-name]# 删除近程分支git push origin --delete [branch-name]

自定义配置

[user]    name = yanyue404    email = xiaoyueyue165@gmail.com    signingkey = ""[credential]    helper = store[http]    postBuffer = 500M    sslBackend = openssl    maxRequestBuffer = 100M[color]    diff = auto    status = auto    branch = auto    ui = true[alias]# 简化命令    br = branch    ci = commit    co = checkout        st = status        mg = merge# 日志    lg = log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit    lgh = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit    lgr = log --color --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --reverse       last = log -10# 回退    back = checkout master    unstage = reset HEAD    rh = reset --hard HEAD# pull    pr = pull --rebase    prs = pull --rebase --autostash[format]    pretty = %C(yellow)%h%Creset %s %C(red)(%an, %cr)%Creset[help]    autocorrect = 1[core]    compression = 0    quotepath = true[i18n]    commitencoding = utf-8    logoutputencoding = utf-8[gui]    encoding = utf-8[merge "ours"]    driver = true

参考

  • http://www.ruanyifeng.com/blo...