美文网首页
git 常用命令

git 常用命令

作者: 板栗炖牛肉 | 来源:发表于2020-12-01 13:34 被阅读0次

    前言

    git 常用命令集,只做随笔,会不断更新

    解决方案

    • 初始化命令
      git init

    • 提交命令
      git add .
      git commit -m 修改信息
      git push origin master -u -f ( -f 强制覆盖更新,-u 应该是记住当前分支信息 之后提交都是直接 git push)

    • 分支查看命令
      git branch -a (-a 查看的更详细)

    • 删除本地分支
      git branch -D master (D大写)

    • 创建本地分支
      git checkout -b master

    • 更新远程分支到本地
      git remote update origin --prune

    • 删除远程分支
      git push --delete origin master

    • 下拉远程分支到本地
      git fetch

    • 合并分支
      git merge origin/master 或 git merge master (合并远程分支 或 本地分支)

    • 下拉合并
      git pull (个人理解为 git fetch 和git merge的集合体,个人不喜欢用这条命令)

    • 添加远程仓库
      git remote add origin URL (origin 是自定义名称,与上诉origin名称一致,我理解为仓库名称,上述master为分支名称)

    • 查看远程仓库
      git remote -v

    • 删除远程仓库
      git remote remove origin

    • 查看git相关信息(不怎么常用)
      git config --global user.name
      git config --global user.email
      git config --list

    • 清除git缓存
      git rm -r --cached .

    • 生成ssh公钥
      ssh-keygen -t rsa -C "邮箱" (git bash 运行)

    • 添加本地tag
      git tag v1.0.0

    • 删除本地tag
      git tag -d v1.0.0

    • 添加远程tag
      git push origin v1.0.0

    • 删除远程tag
      git push origin :refs/tags/v1.0.0

    • 查看本地所有tag
      git tag

    • 清空节点信息(git fetch过慢问题)
      git gc --aggressive --prune=now

    相关文章

      网友评论

          本文标题:git 常用命令

          本文链接:https://www.haomeiwen.com/subject/yqdcvktx.html