git 的安装和使用

安装Git

  • 下载并安装 mysysgit
  • 下载并安装 git windows版本号

配置Git

  • 设置你的名字和邮箱
    git config --global user.name "xxxx"
    git config --global user.email  xx@xxx.com

注:这些配置将出如今git提交日志中,作为Author的标识

  • 很多其它配置可通过运行 git config --help 获得

生成RSA Key

  • 打开git-shell后运行 ssh-keygen -t rsa ,出现提示后所有回车就可以。
  • 将C:/Documents and Settings/<USERNAME>/.ssh/id_rsa.pub。
  • 复制id_rsa.pub中的内容粘帖到github帐号管理中的加入SSH key界面中。

建立本地project

  • 从远程仓库下载代码
    • Java项目:git clone git@git.m.sohuno.com:tpc-arch/sohu-mobile.git本地工作目录
  • 下载完毕后cd 本地工作目录
  • 本地project建立完毕,将project导入IEDA中(推荐使用IEDA10.0,自带了Git的插件)

建立分支流程

  1. git branch <branch name> 该命令仅仅是在本地中建立一个分支
  2. 将本地分支提交到远程分支 git push origin <branch name>

代码合并流程

  1. 切换到master git checkout master
  2. 拉取最新的master代码 git pull origin master
  3. git merge  <branch name>
  4. 合并操作没有问题就能够将本地master提交到远程master git push origin master

以上全部的操作都能够在IDEA中完毕。建议使用IDEA工具运行合并操作,出现冲突时能够可视化的处理冲突

打tag流程

  1. git tag tag_name 创建tag
  2. git push --tags  将tag提交到远程仓库中

Git经常使用命令行操作

  • 建立分支
    git branch <branch name>
  • 从远程更新代码,仅更新,可是不合并到本地分支
    git fetch
  • 从远程更新代码,而且将其合并到当前分支
    git pull origin develop
  • 切换工作文件夹的分支,将工作文件夹的内容切换为指定的分支
    git chekcout <branch name>
  • 将文件增加到git index中,才干够提交
    git add .
  • 提交文件,这里的提交仅仅是提交的本地的仓库中
    git commit
     -a -m "comment"
  • 向远程仓库推送提交的内容
    git push origin develop
  • 打tag
    git tag <tagname>
  • 提交tag到远程仓库
    git push --tags
  • 分支合并指定的分支到当前分支
    git merge <branch name>
  • 衍合,把一条分支上的改动在令一条分支的末梢重现
    git rebase <branch name>
  • 查看帮助,git 内置了强大的帮助功能和智能输入纠错 能够随时查看
    git help
  • 查看本地仓库状态。很实用,建议遇到麻烦时,先使用这个命令*
    git status
  • 比較tag和HEAD之间的不同  

         git diff tag

  • 比較一个文件在两者之间的不同

          git diff tag file

  • 比較两个tag之间的不同

          git diff tag1..tag2

  • 比較一个文件在两个tag之间的不同

         git diff tag1:file tag2:file

原文地址:https://www.cnblogs.com/yangykaifa/p/6921018.html