您的位置:首页 > 其它

Git的使用(一些常用命令)

2017-07-14 15:11 453 查看
Git的基本命令

  1.设置用户名和邮箱

          git config --global user.name "Your Name"  --设置用户名

         git config--globaluser.email "email@example.com
--设置邮箱

 2.常用命令

      git init               --初始化本地仓库

      git add             --将文件提交到暂存区
      git  rm              --将文件删除

      git commit      --将文件提交到当前分支

      git status        --查看当前状态

      git diff              --查看不同

      git checkout  -file  --文件在工作区的操作撤销

      git reset HEAD file   --可以把暂存区的修改撤销掉(unstage),重新放回工作区

3.与远程仓库相关的基本命令

      ssh -keygen -t rsa -C “youremail@example.com”   --生成公钥

      git remote add origin url --连接远程仓库

      git remote set-url origin [url]   --修改远程仓库的URL地址

      git remote rm origin  --删除远程仓库

      git clone   --克隆

      git pull    --从远程仓库中拉取

     git   push  --上传到远程仓库

4.git的分支管理

    git checkout -b dev--创建分支dev–b表示切换

    git branch --看当前分支

    git checkout master  --切换到master分支

    git merge dev--合并指定分支(dev)到当前分支

    git branch -d dev--删除dev分支

     git branch dev–创建dev分支 但不切换

如果两个分支都提交过,此时合并会发生冲突

git stash:    将当前工作现场存储在stash中,以后恢复现场用

git stash list: 查看存储的工作现场

git stash pop: 恢复工作现场同时删除相应的stash内容

git stash apply: 恢复工作现场,但会保留stash内容

git stash apply stash@{0}:    当stash多次时,可以通过git stash list查看这个,恢复相应的工作现场

git stash drop:  删除stash

5.标签

git tag 标签名: 给最新提交的版本打标签

git tag 标签名 commentID: 给log中commentID对应的提交打标签

git tag -a 标签名 -m "描述" commentID: 同时添加描述

git tag:    查看所有标签

git show 标签名:    显示标签的详细信息

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: