一、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. PVRTC 纹理

    iPhone的图形芯片(PowerVR MBX)对一种称为 PVRTC 的压缩技术提供的硬件支持,Apple推荐在开发iPhone应用程序时使用 PVRTC 纹理.他们甚至提供了一篇很好的技术笔记描述 ...

  2. 【Lucene】挖掘相关搜索词

    搜索引擎中往往有一个可选的搜索词的列表,当搜索结果太少时,可以帮助用户扩展搜索内容,或者搜索结果太多的时候可以帮助用户深入定向搜索.一种方法是从搜索日志中挖掘字面相似的词作为相关搜索词列表.另一种方法 ...

  3. centos6.5 eclipse C/C++开发环境

  4. puppet svn集成

    puppet svn集成

  5. aix installp软件包管理工具

    软件可以安装成两种状态:applied和committed.Applied状态保存了原来以前版本的软件,它把以前版本存储在/usr/lpp/PackageName目录下.这种方式可以回滚到以前的软件版 ...

  6. poj1007 qsort快排

    这道题比较简单,但通过这个题我学会了使用c++内置的qsort函数用法,收获还是很大的! 首先简要介绍一下qsort函数. 1.它是快速排序,所以就是不稳定的.(不稳定意思就是张三.李四成绩都是90, ...

  7. JavaWeb学习—Servlet

    1.什么是Servlet Servlet是一个继承HttpServlet类的Java类 Servlet必须部署在web服务器端,用来处理客户端的请求 2.Servlet运行过程 Web Client ...

  8. 2016.09.01 html5兼容

    <!--[if lt IE 9]>  <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min ...

  9. [连载]JavaScript讲义(02)--- JavaScript核心编程

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamFja2ZydWVk/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...

  10. Python学习笔记(十五):类基础

    以Mark Lutz著的<Python学习手册>为教程,每天花1个小时左右时间学习,争取两周完成. --- 写在前面的话 2013-7-24 23:59 学习笔记 1,Python中的大多 ...