Git常用命令

96次阅读
没有评论

Git 常用命令

创建版本库

  1. 克隆远程版本库
    git clone <url>
  2. 初始化本地版本库
    git init

修改和提交

  1. 查看状态
    git status
  2. 查看变更内容
    git diff
  3. 跟踪所有改动过的文件
    git add .
  4. 跟踪指定的问题件
    git add <file>
  5. 文件改名
    git mv <old> <new>
  6. 删除文件
    git rm <file>
  7. 停止跟踪文件但不删除
    git rm --cached <file>
  8. 提交所有更新过的文件
    git commit -m "commit message"
  9. 修改最后一次提交
    git commit --amend

查看提交历史

  1. 查看提交历史
    git log
  2. 查看指定文件的提交历史
    git log -p <file>
  3. 以列表方式查看指定文件
    git blame <file>

撤销

  1. 撤销工作目录中所有未提交文件的修改内容
    git rest --hard HEAD
  2. 修改指定的未提交文件的修改内容
    git checkout HEAD <file>
  3. 撤销指定的提交
    git revert <cimmit>

分支与标签

  1. 显示所有本地分支
    git branch
  2. 切换到指定分支或标签
    git checkout <branch/tag>
  3. 创建新分支
    git branch <new branch>
  4. 删除本地分支
    git branch -d <branch>
  5. 列出所有本地分支
    git tag
  6. 基于最新提交创建标签
    git tag <tagname>
  7. 删除标签
    git tag -d <tagname>

合并与衍合

  1. 合并指定分支到当前分支
    git merge <branch>
  2. 衍合指定分支到当前分支
    git rebase <branch>

远程操作

  1. 查看远程版本库信息
    git remote -v
  2. 查看指定远程版本库信息
    git remote bashow <remote>
  3. 添加远程版本库信息
    git remote add <remote> <url>
  4. 从远程库获代码
    git fetch <remote>
  5. 下载代码及快速合并
    git pull <remote> <brabch>
  6. 上传代码及快速合并
    git push <remote> <branch>
  7. 删除远程分支或标签
    git push <remote> :<branch/tag-namr>
  8. 上传所有标签
    git push --tags
 1
评论(没有评论)
验证码