Git常用命令速查表

创建

  1. 创建一个已存在的仓库。
    git clone git@github.com:LousenJay/DingGong.git
  2. 创建一个新的本地仓库。
    git init

本地修改

  1. 查看工作区当前状态
    git status
  2. 查看工作区与版本库里面最新版本的区别
    git diff
  3. 将工作区当前所有的修改内容添加到暂存区
    git add .
  4. 将工作区指定的修改内容添加到暂存区
    git add <your file>
  5. 将暂存区当前所有的内容都提交到当前分支,并添加注释
    git commit -m "notes"

提交历史

  1. 查看所有的提交历史,从最新的开始
    git log
  2. 查看所有的提交历史,格式化为单行
    git log --pretty=oneline
  3. 查看指定文件的提交历史
    git log -p <filename>
  4. 查看某人某时某刻对指定文件修改了什么
    git blame <filename>

分支和标签

  1. 查看所有已存在的分支,包括远程的
    git branch -av
  2. 切换分支
    git switch <branch>
  3. 创建新的分支
    git branch <branch>
  4. 删除分支
    git branch -d <branch>
  5. 给当前对应commit打标签
    git tag <tag-name>
  6. 删除指定的标签
    git tag -d <tag-name>

更新和推送

  1. 查看当前已配置的远程仓库
    git remote -v
  2. 查看指定远程仓库的信息
    git remote show <remote>
  3. 添加指定的远程仓库
    git remote add <shortname> <url>
  4. 从远程仓库下载所有更新,但是不合并到最新分支
    git fetch <remote>
  5. 从远程仓库下载指定分支的更新,且合并到最新分支
    git pull <remote> <branch>
  6. 将本地修改推送到远程仓库的指定分支
    git push <remote> <branch>
  7. 删除本地仓库与远程仓库对应分支的关联,远程仓库的分支不会被删除
    git branch -dr <remote/branch>
  8. 推送本地所有的标签到远程仓库
    git push --tags

合并

  1. 合并指定分支内容到当前分支上
    git merge <branch>
  2. 使用已经配置好的工具来解决冲突
    git mergetool

回溯

  1. 放弃当前工作区和暂存区所有修改,回溯到版本库最新版本状态
    git reset --hard HEAD
  2. 放弃当前工作区指定文件的修改,回溯到版本库最新版本状态
    git checkout HEAD <filename>
  3. 撤销提交
    git revert commit
  4. 放弃当前工作区和暂存区所有修改,回溯到版本库指定版本
    git reset --hard <commit id>
  5. 保留工作区和暂存区修改,回溯到版本库指定版本
    git reset <commit id>
  6. 保留工作区和指定版本的差异,回溯到版本库指定版本
    git reset --keep <commit id>

最后更新: 2020年07月27日 03:51

原始链接: https://www.lousenjay.top/2020/07/13/从零开始的Git详解(完)/