我在工做中使用 vscode 做为开发编辑器,本地安装了 TortoiseGit 、git bash、Conemu 来使得命令行操做有所减小,可是必要的命令仍是必须的。为了提升操做的效率与使用体验,还作了自定义配置。html
在这里记录一下我经常使用的 Git 命令清单,方便查阅。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] # 取消 rebase git 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