zoukankan      html  css  js  c++  java
  • git入门

    什么是git

    git的分布式版本控制系统,自诞生于 2005 年以来,Git 日臻成熟完善,迅速成为最流行的分布式版本控制系统,在高度易用的同时,仍然保留着初期设定的目标。它的速度飞快,极其适合管理大项目,它还有着令人难以置信的非线性分支管理系统,可以应付各种复杂的项目开发需求。2008年,GitHub网站上线了,它为开源项目免费提供Git存储,无数开源项目开始迁移至GitHub,包括jQuery,PHP,Ruby等等。

    什么是分布式版本控制系统

    说道分布式版本控制系统,我们先来说一下集中式的版本控制系统:

    集中式版本控制系统,版本库是集中存放在中央服务器的,而大家工作的时候,用的都是自己的电脑,所以要先从中央服务器取得最新的版本,然后开始工作,工作完成,再把自己的修订推送给中央服务器。这类系统,都有一个单一的集中管理的服务器,保存所有文件的修订版本,而协同工作的人们都通过客户端连到这台服务器,取出最新的文件或者提交更新。

    现在再来看一下分布式的版本控制系统:

    布式版本控制系统根本没有“中央服务器”,每个人的电脑上都是一个完整的版本库,这样,你工作的时候,就不需要联网了,因为版本库就在你自己的电脑上。既然每个人电脑上都有一个完整的版本库,那多个人如何协作呢?比方说你在自己电脑上改了文件A,你的同事也在他的电脑上改了文件A,这时,你们俩之间只需把各自的修改推送给对方,就可以互相看到对方的修改了。

    GitHub与Git的区别

     GitHub与Git是完全不同的两个东西。在Git中,开发者将代码存入名叫“Git仓库”的资料库中并加以使用。而GitHub则是在网络上提供Git仓库的一项服务。也就是说GitHub上公开的软件源代码全都由Git进行管理。

    GIT下载与安装

    windows下可以去官网下载:https://git-for-windows.github.io/,然后点点即可!

    centos下:yum  -y install git 

    GIT初始化设置

    设置用户名和邮箱

    liubin@DESKTOP-E3SKG7C MINGW64 ~
    $ git config --global user.name "LiuBin"
     
    liubin@DESKTOP-E3SKG7C MINGW64 ~
    $ git config --global user.email "1546893728@qq.com"
    View Code

    这个命令会在用户家目录下生成.gitconfig文件

    liubin@DESKTOP-E3SKG7C MINGW64 ~
    $ cat .gitconfig
    [user]
            email = 1546893728@qq.com
            name = LiuBin
    View Code

    然后就需要去注册一个github账号啦~ 这里就不在敖述~~~~~

    git-ssh配置和使用

    生成密钥

    $ ssh-keygen -t rsa -b 4096 -C "1546893728@qq.com"

    Enter file in which to save the key (/c/Users/liubi/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /c/Users/liubi/.ssh/id_rsa.
    Your public key has been saved in /c/Users/liubi/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:Au44y7WZnG13GQgrfRMCvLXezRpDfuT8E5NQgw6Ssa8 1546893728@qq.com
    The key's randomart image is:
    +---[RSA 4096]----+
    | . .o . |
    | o +.. . o |
    | .+.o o . . |
    | ...+.o + |
    | .o.BSO . . |
    | o. +oO B + |
    | o o.E. * + o |
    | . = *. o o o |
    | o *... . . |
    +----[SHA256]-----+

    然后连续3个回车,出现这些泡泡就代表你成功了。

    然后就会得到一些文件:

    登录Github,添加ssh

    将 id_rsa.pub的内容全部复制到以下:

    两个区域和四个状态

    Git把管理的文件分为两个区域和四个状态

    工作区:

    当前开发程序所在目录称为工作区,即:工作开发都是在该目录,该区域的文件会有状态的变化且状态由git自动检测,如果程序中文件做任何操作(增、删、改),文件状态均会被检测到,可以使用 【git status】命令查看。

    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ ls
    index.html  README.md
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git status
    On branch master
    Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    nothing to commit, working tree clean
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ touch hello.md
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git status
    On branch master
    Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            hello.md
    
    nothing added to commit but untracked files present (use "git add" to track)
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)

    版本库:

    工作区检测到有文件发生变化,那么意味着较上一个版本之后对程序进行了修改,修改完成之后,可以当做下一版本进行提交,那么就是执行 【git add .】 将所有文件提交到暂存区,然后再执行【git commit -m '又一个版本'】提交到版本库的分支即可,之后可以使用【git log】命令查看版本记录。

    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git status
    On branch master
    Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            hello.md
    
    nothing added to commit but untracked files present (use "git add" to track)
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git add .
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git status
    On branch master
    Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
      (use "git pull" to update your local branch)
    
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
            new file:   hello.md
    
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git commit -m "second commit"
    [master b123c2e] second commit
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 hello.md
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)
    $ git log
    commit b123c2ee3071f1142468b2ba63f23ea4df06125b (HEAD -> master)
    Author: liubin <1546893728@qq.com>
    Date:   Fri Mar 16 00:24:40 2018 +0800
    
        second commit
    
    commit bd9be8890fbd283adb8d1c43120006cb47c33baf
    Author: liubin <1546893728@qq.com>
    Date:   Thu Mar 15 23:36:00 2018 +0800
    
        新增index
    
    commit 6db481f7247bcf81353cefefb50054a329aaba9a
    Author: liubin <1546893728@qq.com>
    Date:   Thu Mar 15 23:25:57 2018 +0800
    
        first commit
    
    liubi@DESKTOP-9HC44IV MINGW64 /e/项目/grg/blog (master)

     GIT常用的基础命令

    • git init:初始化,表示即将对当前文件夹进行版本控制。
    • git status:查看Git当前状态,如:那些文件被修改过、那些文件还未提交到版本库等。
    • git add  filename:将指定文件添加到版本库的暂存状态。
    • git commit -m '提交信息':将暂存区的文件提交到版本库的分支。
    • git log:查看提交记录。

     基础入门就到这里了,关于更多的git的知识,请见以后的博客或者参考官网的book: https://git-scm.com/book/zh/v2 

  • 相关阅读:
    二叉树相关题目
    二叉树的遍历
    mysql获取某个表中除了某个字段名外的所有字段名
    设计模式之原型模式
    设计模式之工厂方法模式
    设计模式之代理模式
    设计模式之装饰模式
    设计模式之策略模式
    设计模式之简单工厂模式
    Redis的使用及参考代码
  • 原文地址:https://www.cnblogs.com/liubinsh/p/8577304.html
Copyright © 2011-2022 走看看