一、git安装、配置

  git安装:

    root@ubuntu~# apt-get  install  git

  git配置githup/自己的git服务器端账号, 即在用户的home目录下生成.gitcofig文件,可手动修改:

    root@ubuntu~# git config --global user.name "Your Name Here"      

    root@ubuntu~# git config --global user.email your_email@example.com

    root@ubuntu~# git config --global color.ui true

  查看已有的配置信息:

    root@ubuntu~# git config --list

二、git使用:

  git创建仓库(repository,老外简写repo):

    新建项目目录,eg: cd  /root/mygit

      1、首次将本地的项目初始化到git服务器:

        root@ubuntu~# git init    #创建一个空的repository,在当前目录下生成了.git文件夹

        root@ubuntu~# git add *

        root@ubuntu~# git commit -m 'initial project version'

        root@ubuntu~# git remote add origin git@github.com:username/project_name.git     # 即刚刚创建的仓库的地址

        root@ubuntu~# git push -u origin master                          #推送代码到远程代码库

      2、将git服务器代码初始化到本地:      

        root@ubuntu~# git clone git_address                           #把GitHub里的项目复制到本地    
  git添加及提交
    root@ubuntu~#git  add   demo.py                                 #添加demo.py文件

    root@ubuntu~#git status                                     #查看状态 

    root@ubuntu~#git commit  -m "log here"  #不加参数-m,则默认使用vi打开一个文件写入log      #等同于svn的commit 

    root@ubuntu~#git status

          _______________________________
| |
| histroy |
|_______________________________|
|
|
| git commit
_______________|_______________
| |
| staging area |
|_______________________________|
|
|
| git add
________________|_______________
| |
| working dir |
|_______________________________|

   root@ubuntu~#git status -s    #查看三者之间的是否相同,标记位:M , MM,

   root@ubuntu~#git diff       #比较working dir 与staging area之间的差异

   root@ubuntu~#git diff   --staged    #比较staging area 与 history之间的差异,用于add之后检测

  撤销误操作:

   root@ubuntu~#git add demo    #add一版代码到staging area

   root@ubuntu~#git status -s     

   M   demo

   root@ubuntu~#git  reset demo   #将history中的demo覆盖staging area

   root@ubuntu~#git checkout demo    #将staging area中文件覆盖到working dir

   直接从history覆盖到working dir:

   root@ubuntu~#git  checkout HEAD demo

    同理将working dir中改动直接提交到history:

   root@ubuntu~#git  commit -am "update log"

 删除以及重命名:

     root@ubuntu~#git rm  demo

   root@ubuntu~#git status -s

   root@ubuntu~#git commit -m 'delete demo'

  保存working dir中的demo文件

   root@ubuntu~#git rm --cached demo    #只是把staging area中demo删除了

   root@ubuntu~#git reset demo        #把history中的demo覆盖到staging area中

   root@ubuntu~#git  mv demo demo.bak   #把working dir和staging area中重命名

   root@ubuntu~#git commit -m 'rename demo' #history也重命名了

   root@ubuntu~# git rm --cached demo.bak  #只修改了staging area部分

   root@ubuntu~#mv demo.bak demo

   root@ubuntu~#git add demo

   root@ubuntu~#git status -s

   root@ubuntu~#git commit -m 'rename demo.bak'

  赞存工作区:在代码修改之后,马上需要在原版本上修改bug,此时就可以将此时的工作区临时保存起来;

    root@ubuntu~#git stash    #此时working dir是history中的内容

    root@ubuntu~#vim  demo

    root@ubuntu~#git commit  -am 'quick fix'  #紧急提交,修改bug

    root@ubuntu~#git stash list         

    root@ubuntu~#git  stash pop         #将临时工作区恢复到working dir

 分支管理:

    root@ubuntu~# git  branch          #列出当前所有分支

    * master                    #*表示当前使用的分支
    root@ubuntu:~# git branch try_idea      #创建branch
    root@ubuntu:~# git branch
    * master
      try_idea
    root@ubuntu~# git checkout try_idea      #切换到try_idea分支
    D    aaa.py
    Switched to branch 'try_idea'
    root@ubuntu-ceph-06:~/cp/git# git branch
     mater
    * try_idea                     #当前分支

    root@ubuntu~#git branch -d  try_idea       #删除分支

    联合操作,创建分支并切换到新建的分支上:

    root@ubuntu~#git checkout -b try_idea

  版本合并:

    root@ubuntu~#git branch mybranch      

    root@ubuntu~#git checkout mybranch

    root@ubuntu~#vim  demo          #做下修改;

    root@ubuntu~#git commit -am "mybranch commit"

    root@ubuntu~#git  checkout master

    root@ubuntu~#git  merge  mybranch    #将mybranch分支合并到master分支

    root@ubuntu~#git branch -d mybranch   #只有在合并之后才能删除分支,否则报错

分支版本合并:如图

                                                   master branch
____ ____ ____ ____
| | | | | | | |
| a | <--- | b | <--- | c | <---- | e |
|____| |____| |____| |____|
|
| bugfix branch
__|_ ____
| | | |
| d | <---- | f |
|____| |____|

    root@ubuntu~#git merge  buffix      #在master版本上,并提交版本,到达了e版

    出现需要合成临时版本的情况,即c版合并f版,生成临时版本之后,再于e版本合并;

    出现的对话框,选择ctrl+x即可;若有冲突则提交不成功;需要手动vim修改

git log, 如果嫌输出信息太多,看得眼花缭乱的,可以试试加上--pretty=oneline参数:

用带参数的git log也可以看到分支的合并情况: 

 root@ubuntu-ceph-:~/cp/mygit# git log --graph --pretty=oneline --abbrev-commit
* f0be77e configct fixed
|\
| * 290e5e3 change master
| * c539383 branche test
* | a315058 aa.txt
|/
* e51e421 msg
* 6c84560 init msg

git分枝策略:

git、githup使用的更多相关文章

  1. 1.Git & GitHup

    1.常见的版本控制(管理代码的版本迭代)工具: @ svn:集中式版本控制系统: SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是自己的电脑,所以首先要从中央服务器哪里 ...

  2. JAVA视频链接

    Java基础Java马士兵:链接:https://pan.baidu.com/s/1jJRvxGi密码:v3xb Java刘意:链接:https://pan.baidu.com/s/1kVZQCqr密 ...

  3. Java视频教程免费分享(网盘直接取)

    Java基础 Java马士兵:链接:https://pan.baidu.com/s/1jJRvxGi密码:v3xb Java刘意:链接:https://pan.baidu.com/s/1kVZQCqr ...

  4. git学习记录——远程仓库(说白了就是代码放到githup上)

    远程仓库 现在讲述的这些SVN都已经做到了,并没什么稀奇的地方 所以这节课赘述的是杀手级的东西——远程仓库githup ssh-keygen -t rsa  -C "xxxxxxxxxxx@ ...

  5. git关联githup和码云

    1.与已有的本地仓库关联git remote add origin git@github.com:michaelliao/learngit.git然后就可以协作开发push与pull 2.第二种方法直 ...

  6. git的使用学习(七)githup和码云的使用

    1.使用GitHub 我们一直用GitHub作为免费的远程仓库,如果是个人的开源项目,放到GitHub上是完全没有问题的.其实GitHub还是一个开源协作社区,通过GitHub,既可以让别人参与你的开 ...

  7. git和githup

    一:Git简介 1.1:VCS的历史 Git是一款代码管理工具(Version Control System),傲视群雄,是目前世界上最先进的免费开源的分布式版本控制系统,没有之一! VCS版本控制系 ...

  8. git分布式版本控制玩法

    git分布式版本控制玩法 Git distributed version control play github的配置安装步骤:1.下载git bash(从http://www.git-scm.com ...

  9. Git下载Spring项目源码并编译为Eclipse

    1)当前系统中安装了gradle,如果为安装,可以从:http://www.gradle.org/downloads,,下载完后进行解压到任意盘符,然后增加环境变量GRADLE_HOME,并在环境变量 ...

随机推荐

  1. [转]前端利器:SASS基础与Compass入门

    [转]前端利器:SASS基础与Compass入门 SASS是Syntactically Awesome Stylesheete Sass的缩写,它是css的一个开发工具,提供了很多便利和简单的语法,让 ...

  2. nodejs递归创建目录,同步和异步方法

    nodejs递归创建目录,同步和异步方法.在官方API中只提供了最基本的方法,只能创建单级目录,如果要创建一个多级的目录(./aaa/bbb/ccc)就只能一级一级的创建,感觉不是很方便,因此简单写了 ...

  3. 前端js模板库 JinkoTemplate

    有时候需要使用ajax来异步生成html,最土的方法就是用js的‘+’连接html代码,生成繁琐.一旦需要修改,对于少量的html代码到没啥问题,要是比较复杂的样式时,就真坑爹了,眼花缭乱有木有?Ji ...

  4. Javascript 排序数组或对象

    分享一个用于数组或者对象的排序的函数.该函数可以以任意深度的数组或者对象的值作为排序基数对数组或的元素进行排序. 代码如下: /** * 排序数组或者对象 * by Jinko * date 2015 ...

  5. LeetCode-001 Two Sum

    [题目] Given an array of integers, find two numbers such that they add up to a specific target number. ...

  6. java web从零单排第十七期《struts2》数据标签库(1)

    1.s:action标签: 此标签的作用是在JSP页面中访问action类的数据,执行某些操作,并返回相应的数据.其属性及意义如下: 属性名 是否必需 默认值 类型 说明介绍 executeResul ...

  7. D3学习教程

    [ D3.js 入门系列 ] 入门总结 | OUR D3.JS http://www.ourd3js.com/wordpress/?p=396

  8. EF实体框架-从数据库更新模型 一部分表的外键(导航属性)无法显示

    从数据库更新模型 要想让数据库表之间的外键关系 显示到实体模型的导航属性中去. 表的外键 对应另一张表的字段要是主键,唯一键显示不出来

  9. Virtualbox 启动虚拟机报错以及扩展、显卡驱动安装

    一.Virtualbox虚拟机启动报错,如图 预先估计是BIOS中的cpu Virtualtion虚拟化支持是disable,结果一看是enable. 接下来只好Google,找到了这么一个帖子:ht ...

  10. 与后台进行连接,mysql模块 第六篇

    var mysql = require("mysql"); var client = function(sql, callback) { var db = mysql.create ...