git (1)

1、git是什么

  git是一种版本控制器,更直白说,团队开发是,管理代码用的软件。

2、安装

  Windows环境下安装:

  到:https://git-for-windows.gitup.io/下载软件,双击,一路“next”,安装完毕。

  通过“开始”菜单,进入git bash窗口。

3、配置用户名和联系邮箱:

 $ git config --global  user.name  #用户名

 $   git config --global  user.email    #联系邮箱

4、代码管理

    4.1创建版本库

      $ cd E:/

      $ mkdir test

      $ cd E:/test

    注意:

      1)不要把仓库建在中文目录下,可能出问题

      2).git 是个隐藏目录,不要乱碰(你的每一次代码修改它都帮你记录着呢)

    4.2添加文件

      在E:/test目录下,用你喜欢的编辑器(sublime/editplus等),

      开发你的程序,比如,index.php

      $ git init 

      $ git status

      可见,此时git发现有一个新文件,但并没有把此文件纳入管理。

      我们需要两步,让git仓库管理index.php

      a、$ git add index.php

        把index.php提交到暂存区

      b、$ git commit -m "新建index.php"

        把index.php提交到版本库

    

    4.3修改文件

     如果修改了文件,也不要忘记提交到版本库

     这个过程和添加文件是一样的

      一样是需要两步,让git仓库记录此次改变

      a、$ git add index.php

        把index.php提交到暂存区

      b、$ git commit  -m "改了第2行"

        把index.php提交到版本库

      

      4.4删除文件

      用rm命令删除文件,并直接commit,提交到版本库

      例:先创建一个foo.php

      $ touch foo.php  #创建foo.php

      $ git add  foo.php

      $  git  commit  -m "练习删除用"

      $ ls

        foo.php  index.php

      #开始删除

      $ git rm  foo.php

      $ git commit -m "删除foo.php" 

      $ ls

         index.php

  5、远程仓库

  开发者把自己最新的版本推到线上仓库。

  同时,把线上仓库的最新代码,拉到自己本地。

  这样就可以配合工作了。

     5.1注册git在线仓库账号

      国外:http://www.gitub.com

      国内:http://www.git.oschina.net

      此处演示用国内账号:

      5.2创建项目

      创建项目,oschina为此项目提供的仓库地址有2个。

      http地址:https://git.oschina.net/.....

      ssh地址:git@git.oschina.net:.....

      此处用http地址:

      5.3把代码推到远程仓库

        推:push

        进入本地文件目录:

        a、为本地库添加远程库

          $ git remote  add origin  https://git.oschina.net...

          意思是添加1个远程库,代号是origin,地址是https://git.oschina.net....

        b、push推代码

          push  origin master

          意思是,把本地的版本(默认是master),推到代号为origin的远程库区

          这个过程会让你输入用户名和密码,即注册账号和密码。

      

原文地址:https://www.cnblogs.com/flytime/p/6872796.html