[关闭]
@rickyChen 2018-05-09T06:36:33.000000Z 字数 1791 阅读 1755

Git 版本管理

Git


  1. 安装

    1. yum install git
    2. //建议安装版本>1.8
  2. 简易的命令行入门教程

    • Git全局设置:

      1. git config --global user.name "RickyHuo"
      2. git config --global user.email "huochen1994@163.com"
      3. //配置git当前用户信息
    • 创建git仓库:

      1. mkdir test
      2. cd test
      3. git init
      4. //将当前目录初始化
      5. touch README.md
      6. git add README.md
      7. //把README.md添加到git管理
      8. git commit -a -m "first commit"
      9. //将修改保存到本地库中,双引号内为本次提交注释内容
      10. git remote add origin https://github.com/apache/spark.git
      11. //在git服务器新建一个源于当前目录连接
      12. git push -u origin master
      13. //将最新的修改同步到git服务器端的master分支
    • 已有项目?

      1. git clone https://github.com/apache/spark.git
      2. touch README.md
      3. //从远端下载文件
      4. git commit -a -m "update ..."
      5. git push -u origin master
    • 理解并使用分支
      使用分支可以让你从开发主线上分离开来,然后在新的分支上解决特定问题,同时不会影响主线

      1. git branch (-a)
      2. //显示当前所在分支(显示该项目所有分支)
      3. git branch testing
      4. //创建一个名为testing的分支
      5. git checkout (-b) testing
      6. //切换到testing分支(创建并切换到testing分支)
      7. git branch -d testing
      8. //删除testing分支,仅删除本地,不删除远端分支
      9. git branch -m oldbranch newbranch
      10. //重命名分支
      11. git merge (--no-ff) branch1
      12. //将branch1分支合并到当前分支
      13. //--no-ff:保留分支的commit历史
      14. git push origin --delete branch1
      15. git push origin :branch1
      16. //删除远端的分支
    • 版本回退

      1. git checkout -f filename
      2. //撤销该文件在工作区的修改
      3. git reset HEAD filename
      4. //撤销该文件在暂存区的修改
      5. git reset --hard xxx
      6. //版本回退,回退到commit点为xxx的版本
    • 其他命令

      1. git status
      2. //可以列出当前目录所有还没有被git管理的文件和被git管理且被修改但还未提交(git commit)的文件.
      3. git diff
      4. //列出当前目录于最新的commit点的不同
      5. git diff a b
      6. //列出变量a和b的不同,其中变量可为commit信息、版本信息等
      7. git log
      8. //列出之前所有commit记录
      9. git reflog
      10. //列出所有commit历史记录
      11. git commit --amend --reset-author
  3. 快捷键设置

    1. vim ~/.bashrc
    2. #git alias
    3. alias gl='git log --graph --oneline --decorate'
    4. alias gl2='git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --graph'
    5. alias gbr='git branch'
    6. alias gcb='git checkout'
    7. alias gnb='git checkout -b'
    8. alias gcm='git commit -a'
    9. alias gsta='git status -s'
    10. source ~/.bashrc
  4. 颜色设置

    1. git config --global color.status auto
    2. git config --global color.diff auto
    3. git config --global color.branch auto
    4. git config --global color.interactive auto
  5. references

    git - 简易指南
    http://www.bootcss.com/p/git-guide/
    Git -Documentation
    http://git-scm.com/doc
    github - Hello World
    https://guides.github.com/activities/hello-world/

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注