Git 常用命令 和 安装

安装

  • Windows版:https://git-scm.com/download/win ,下载完成后就自己手动安装 。
  • Ubuntu版:直接在命令行实行apt-get install git , 他自己结束

命令

  • 创建密钥, 然后自己将密钥放到自己GitHub上

    shh-keygen -t  rsa -C  "zhengquantao@gmail.com"
    
  • 连接项目 下载到本地

    git clone git@github.com:zhengquantao/vue-kline.git
    
  • 设置上传名

    git config  -- global user.name 'taozhengquan' 
    
  • 查看分支

    git branch
    
  • 分支重命名

    git branch -m oldName  newName
    
  • 将file加入暂存区

    git add file
    
  • 提交到仓库 后面是说明

    git commit -m 'first commit to store'
    
  • 推上仓库

    git push origin master
    
  • 强制覆盖远程master仓库

    git push origin master --force
    
  • 从远程仓库上拉取数据,会自动merge

    git pull origin master
    
  • 从远程仓库获取分支,不会自动merge

    git fetch origin test/1022
    
  • 合并分支

    git merge test/1022
    
  • 强行覆盖本地分支

      git fetch origin test/1022
      git reset --hard test/1022
    
  • 切换分支

    git checkout master
    
  • 切换分支,不存在创建

    git checkout -b master
    
  • 查看提交历史

    git log
    
  • 查看暂存区信息

    git status
    
  • 将仓库回到缓存中 ^是要恢复的版本 最近HEAD

    git reset HEAD^^^
    
  • 将当前分支基于master分支

    git rebase master
    
  • 合拼3个提交

    git rebase -i HEAD~3
    
  • 更改提交信息

    git commit --amend
    
  • 删除远程test/0122分支

    git push origin --delete test/0122
    
  • 删除本地test/0122分支

    git branch -d test/0122
    
  • 将改动信息暂存

    git stash
    
  • 将暂存信息恢复

    git stash pop
    
posted @ 2018-12-14 23:25  TY520  阅读(24366)  评论(0编辑  收藏  举报