• Git 简介及简单操作


    git简介

    Git(读音为/gɪt/。)是一个开源的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。

    Git和SVN对比

    1. git是分布式的,svn是集中式的。(最核心)
    2. git是每个历史版本都存储完整的文件,便于恢复,svn是存储差异文件,历史版本不可恢复。(核心)
    3. git可离线完成大部分操作,svn则不能。
    4. git有着更优雅的分支和合并实现。
    5. git有着更强的撤销修改和修改历史版本的能力
    6. git速度更快,效率更高。
    7. 基于以上区别,git有了很明显的优势,特别在于它具有的本地仓库。

    Git的几个概念

    1. 工作目录
      工作目录是对项目的某个版本独立提取出来的内容。这些从 Git 仓库的压缩数据库中提取出来的文件,放在磁盘上供你使用或修改。
    2. 暂存区域
      是一个文件,保存了下次将提交的文件列表信息,一般在 Git 仓库目录中。有时候也被称作`‘索引’’,不过一般说法还是叫暂存区域
    3. Git仓库
      是Git 用来保存项目的元数据和对象数据库的地方。这是 Git 中最重要的部分,从其它计算机克隆仓库时,拷贝的就是这里的数据。

    Git安装

    yum install git -y  #本地源即可
    

    Git命令

    常用选项

    add   #把工作目录内容添加到暂存区域
    branch   #查看和设置分支
    checkout   #切换分支和撤销
    clone   #克隆远程仓库
    commit   #把暂存区域内容提交到仓库
    init   #初始化工作目录
    log   #查看提交的日志信息
    merge   #合并分支
    pull   #拉取远程仓库
    push   #把本地内容推送到远程仓库
    reset   #撤销操作
    status   #查看文件所处的状态
    

    git使用演示

    第一步:创建和初始化工作目录

    ╭─root@localhost.localdomain ~  
    ╰─➤  mkdir /du
    ╭─root@localhost.localdomain ~  
    ╰─➤  cd /du
    ╭─root@localhost.localdomain /du  
    ╰─➤  git init
    Initialized empty Git repository in /du/.git/
    ╭─root@localhost.localdomain /du  ‹master› 
    ╰─➤  ls -a
    .  ..  .git
    
    

    第二步:创建文件进行测试

    [root@localhost du]# git add .       #提交所有文件到暂存区域
    [root@localhost du]# git commit -m "v1"        #提交到仓库并命名为v1
    [master (root-commit) 87e3407] v1
     Committer: root <root@localhost.localdomain>
    Your name and email address were configured automatically based
    on your username and hostname. Please check that they are accurate.
    You can suppress this message by setting them explicitly:
    
        git config --global user.name "Your Name"
        git config --global user.email you@example.com
    
    After doing this, you may fix the identity used for this commit with:
    
        git commit --amend --reset-author
    
     1 file changed, 1 insertion(+)
     create mode 100644 test
    
    [root@localhost du]# git log      #  查看版本信息
    commit 87e34070f1826f81e7cece30996d8f74c99380ab
    Author: root <root@localhost.localdomain>
    Date:   Thu Oct 10 07:53:15 2019 -0400
    
        v1
    
    

    第三步:版本测试

    [root@localhost du]# echo "123" >> test    #修改并提交
    [root@localhost du]# git add .
    [root@localhost du]# git commit -m "v2"
    [master dd49644] v2
     Committer: root <root@localhost.localdomain>
    Your name and email address were configured automatically based
    on your username and hostname. Please check that they are accurate.
    You can suppress this message by setting them explicitly:
    
        git config --global user.name "Your Name"
        git config --global user.email you@example.com
    
    After doing this, you may fix the identity used for this commit with:
    
        git commit --amend --reset-author
    
     1 file changed, 1 insertion(+)
    
    
    [root@localhost du]# echo "456" >> test     #再次修改并提交
    [root@localhost du]# git add test
    [root@localhost du]# git commit -m "v3"
    [master 7bf0e8a] v3
     Committer: root <root@localhost.localdomain>
    Your name and email address were configured automatically based
    on your username and hostname. Please check that they are accurate.
    You can suppress this message by setting them explicitly:
    
        git config --global user.name "Your Name"
        git config --global user.email you@example.com
    
    After doing this, you may fix the identity used for this commit with:
    
        git commit --amend --reset-author
    
     1 file changed, 1 insertion(+)
    
    
    [root@localhost du]# git log       #查看版本信息
    commit 7bf0e8a2ffcf59c6d41305aa30daa6316b32e394
    Author: root <root@localhost.localdomain>
    Date:   Thu Oct 10 07:59:54 2019 -0400
    
        v3
    
    commit dd49644861b398cc77cb2de624e02d2abf43e52d
    Author: root <root@localhost.localdomain>
    Date:   Thu Oct 10 07:59:21 2019 -0400
    
        v2
    
    commit 87e34070f1826f81e7cece30996d8f74c99380ab
    Author: root <root@localhost.localdomain>
    Date:   Thu Oct 10 07:53:15 2019 -0400
    
        v1
    
    

    gitlab

    gitlab简介

    • GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
    • 可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,
    • 管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。
    • 团队成员可以利用内置的简单聊天程序(Wall)进行交流。
    • 它还提供一个代码片段收集功能可以轻松实现代码复用。

    Command line instructions

    Git global setup

    git config --global user.name "Administrator"
    git config --global user.email "admin@example.com"
    

    Create a new repository

    git clone git@192.168.137.4:root/test.git
    cd test
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master
    

    Existing folder or Git repository

    cd existing_folder
    git init
    git remote add origin git@192.168.137.4:root/test.git
    git add .
    git commit
    git push -u origin master
    

  • 相关阅读:
    身份目录即服务DaaS如何解决企业设备退化问题?
    企业要部署微软 AD 应该考虑哪些问题?
    传统用户管理方案有哪些利弊?
    无线网络存在的安全问题及现代化解决方案
    如何应用基于条件访问策略的多因子认证(MFA)?
    test
    linux下禁止root用户登录,修改远程ssh登录端口号 孙龙
    linux mysql 5.7.11 手动安装
    java——异常——Objects非空判断
    java——异常——抛出throw关键字
  • 原文地址:https://www.cnblogs.com/du-z/p/11191109.html
Copyright © 2020-2023  润新知