1. git常用命令

  • git clone <url>: 克隆远程仓库到本地
    • git clone --recursive <url>: 克隆远程仓库到本地,包括子模块
    • vim .gitmodules: 查看子模块信息
  • git init: 初始化本地仓库
  • git add <file>: 添加文件到暂存区
    • git add .: 添加所有文件到暂存区
  • git commit -m <message>: 提交暂存区到本地仓库
  • git status: 查看本地仓库状态
  • git log: 查看提交日志
  • git branch <branch_name>: 创建分支
  • git checkout <branch_name>: 切换分支
  • git checkout -b <branch_name>: 创建并切换分支
  • git branch -d <branch_name>: 删除分支
  • git branch -a: 查看所有分支
  • git branch -vv: 查看所有分支与远程分支的连接关系
  • git merge <branch_name>: 合并分支
  • git remote: 查看当前连接的远程仓库
  • git remote -v: 查看当前连接的远程仓库详细信息
  • git remote add <remote_name> <url>: 添加远程仓库
  • git remote remove <remote_name>: 删除远程仓库
  • git remote set-url <remote_name> <url>: 修改远程仓库地址
  • git remote rename <old_name> <new_name>: 修改远程仓库别名
  • git fetch <remote_name>: 拉取远程仓库
    • git fetch: 拉取当前连接的远程仓库
    • note:git fetch拉取后不会对本地仓库进行改变,如需改变,需要使用git mergegit rebase
  • git pull <remote_name> <branch_name>: 拉取远程仓库到本地仓库
    • git pull: 拉取当前连接的远程仓库到本地仓库
    • note:git pull会改变本地仓库
  • git push <remote_name> <branch_name>: 推送本地仓库到远程仓库
    • git push: 推送当前分支到远程仓库
  • git push <remote_name> <branch_name>:<remote_branch_name>: 推送本地仓库到远程仓库的指定分支
  • git push <remote_name> --delete <branch_name>: 删除远程仓库的指定分支
  • git reset --hard <commit_id>: 回退到指定commit版本
  • git reset --hard HEAD^: 回退到上一个commit版本
  • git reset --hard HEAD~n: 回退到前n个commit版本
  • git reset --hard <commit_id>: 回退到指定commit版本`
  • git tag <tag_name> <commit_id>: 给指定commit打标签
  • git tag -a <tag_name> -m <message>: 给当前commit打标签
  • git tag -d <tag_name>: 删除指定标签