当前位置:   article > 正文

学习 Git与GItlab_git的作用

git的作用

1.git工具使用

Git作用:git的作用就是对文件进行版本管理,方便在不同版本进行切换修改

Git特点:

  • 速度
  • 简单的设计
  • 对非线性开发模式的强力支持(允许成千上万个并行开发的分支)
  • 完全分布式
  • 有能力高效管理类似 Linux 内核一样的超大规模项目(速度和数据量)

自诞生于 2005 年以来,Git 日臻成熟完善,在高度易用的同时,仍然保留着初期设定的目标。 它的速度飞快,极其适合管理大项目,有着令人难以置信的非线性分支管理系统。

Git必看秘籍:https://git-scm.com/book/zh/v2

安装Git

  1. # yum install -y git
  2. # mkdir demo
  3. # cd demo
  4. # git init 版本初始化

  1. # git config --global user.email "yueyue@cc.com" 新建用户邮件
  2. # git config --global user.name "yueyue" 新建用户名
  3. # git status -s
  4. # git status 查看状态
  5. # git add README 添加到暂存区
  6. # git checkout -- README 撤销对文件的修改
  7. # git commit 提交更新

练习:

提交:

  1. # touch README
  2. # echo westos > README 写入内容
  3. # git status -s

  1. # git add README 添加
  2. # git status -s

  1. # git commit -m "v1" 提交缓存区的内容
  2. # git log 查看提交历史

# git commit -a -m 'added new benchmarks'  跳过缓存区提交

删除:

  1. [root@localhost demo]# git rm FILE
  2. [root@localhost demo]# git commit -m v4

撤销:

  1. [root@localhost demo]# echo haha >> westos
  2. [root@localhost demo]# git checkout -- "westos" 撤销

2.远程仓库

注册github帐号,并新建一个仓库(http://www.gittub.com或者 http://gitee.com)

在虚拟机中生成秘钥,并复制

# ssh-keygen

免密成功

  1. [root@localhost demo]# git remote add origin git@github.com:byueyue/demo.git (选择ssh,如果选择了https就不可以在添加ssh了可以执行 # git remote rm origin)
  2. # git remote -v
  3. [root@localhost demo]# git push -u origin master

测试:将本地目录删除后,可以从远程仓库克隆下载

# git clone git@github.com:byueyue/demo.git  

3.Gitlab的安装

官网:https://about.gitlab.com/install/

软件下载(官方下载慢,推荐使用国内镜像站点)
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/


软件安装: (官方推荐至少4G内存)

  1. # yum install -y curl policycoreutils-python openssh-server
  2. # rpm -ivh gitlab-ce-12.9.7-ce.0.el7.x86_64.rpm

修改配置文件

  1. # vim /etc/gitlab/gitlab.rb   修改完必须重新加载文件
  2. # gitlab-ctl gitlab-ctl reconfigure 重新加载

       

# gitlab-ctl status  查看状态

登录gitlab: 
http://172.25.0.11         //用户:root 第一次登录需要强制修改密码

 添加ssh免密

 

添加项目

使用ssh克隆

# git clone git@172.25.254.6:root/demo.git (注意seliunx和防火墙状态)

上传文件、

  1. # touch index.html
  2. # git add index.html
  3. # git -m "add index.html" 添加到缓存
  4. # git commit -m "add index.html" 跟新
  5. # git push -u origin master 上传

查看:

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/735227
推荐阅读
相关标签
  

闽ICP备14008679号