其他分享
首页 > 其他分享> > Pro Git --- 读书笔记 (Chaptero5)

Pro Git --- 读书笔记 (Chaptero5)

作者:互联网

附录C:Git命令

配置默认编辑器
git config --global core.editor "xxx"
配置提交时的用户名称和邮箱
git config --global user.name "xxx"
git config --global user.email xxx.com
配置Git命令的别名
git config --global alias.xx 'xxx'
新建一个仓库
git init
克隆一个仓库
git clone [-o [remoteName]] <url>
从工作目录到暂存区
git add [./file]
查看状态
git status
查看任意两棵树的差异
  1. 工作区和暂存区的差异
git diff
  1. 暂存区和最后提交的差异
git diff --staged
  1. 两个提交之间的差异
git diff <branch> <branch>
  1. 查看分支之间的某段差异
git diff A..B
// 大于A小于B,即存在于B但不在A中的差异
提交
  1. 简单提交
git commit -m ‘xxx’
  1. 跳过add提交
git commit -a -m 'aaa'
// 将已跟踪文件的修改全部加入暂存区,然后提交
  1. 重做提交
git commit --amend
// 合并最后一次提交的信息
重置
  1. 重置HEAD
git reset --soft <commit hash>
  1. 重置HEAD和暂存区
git reset --mixed <commit hash>
  1. 全部重置
git reset --hard <commit hash>
分支
  1. 创建一个新分支
git branch <branch>
  1. 分支查看
git branch [-v] [-vv]
  1. 分支删除
git branch -d <branch>
  1. 查看和当前分支有没有合并的分支
git branch [--merged] [--no-merged]
  1. 指定跟踪分支
git branch -u <remote>/<branch>
分支检出
  1. 分支切换
git checkout <branch>
  1. 创建分支并切换
git checkout -b <branch>
  1. 创建或切换分支并指定跟踪分支
git checkout -b <branch> <remote>/<branch>
合并
  1. 分支合并
git merge <branch>
  1. 单独合并某一个提交的差异到当前分支
git cherry-pick <commit hash>
提交历史
  1. 查看历史,默认从当前分支的最近提交开始
git log
  1. 限制查看数量
git log -<num>
  1. 查看每次提交所引入的差异
git log -p
  1. 限制格式化
git log --pretfen zhi
git log --author
  1. 关键字匹配
git log --grep 
贮藏
  1. 贮藏暂存区和工作目录
git stash
  1. 查看所有贮藏
git stash list
  1. 应用贮藏
git stash apply
  1. 指定应用贮藏
git stash apply stash@{num}
  1. 暂存区恢复
git stash apply --index
  1. 删除贮藏
git stash drop stash@{num}
  1. 应用并丢弃
git stash pop
  1. 从贮藏创建分支
git stash branch <branch>
拉取
  1. 抓取
git fetch <remote>
拉取并合并
  1. 拉取合并
git pull
推送
  1. 推送
git push <remote> <branch>
远程仓库管理
  1. 查看远程仓库
git remote [-v]
  1. 添加远程仓库
git remote add <name> <url>
  1. 查看某个远程仓库
git remote show <remote>
  1. 重命名远程仓库的本地记号
git remote rename <old> <new>
  1. 删除远程仓库
git remote remove <remote>
变基
  1. 变基合并
git rebase <base> <topic>
  1. 三分支变基
git rebase --onto <b1> <b2> <b3>
数据恢复
  1. 查找丢失的commit
// 简单信息
git reflog
// 详细信息
git log -g
// 最后手段
git fsck --full
  1. 分支指向一个commit
git branch <branch> <commit>

标签:git,读书笔记,--,Pro,stash,---,暂存区,提交,分支
来源: https://www.cnblogs.com/huangwenhao1024/p/16297475.html