网站建设公司-信科网络,seo排名关键词搜索结果,深圳网站建设 推广,西部数码里面如何建设自己的网站目录 一、Git介绍二、Git安装与全局配置1、git的全局配置#xff1a;2、为常用的指令配置别名#xff1a;3、Git初始化本地代码仓库4、Git的基础命令 三、分支四、Git远程仓库1、操作远程仓库2、从远程仓库克隆3、从远程仓库中抓取和拉取 五、Gitlab sever部署期间出现遇到的… 目录 一、Git介绍二、Git安装与全局配置1、git的全局配置2、为常用的指令配置别名3、Git初始化本地代码仓库4、Git的基础命令 三、分支四、Git远程仓库1、操作远程仓库2、从远程仓库克隆3、从远程仓库中抓取和拉取 五、Gitlab sever部署期间出现遇到的问题 六、Gitlab使用 一、Git介绍
Git是一个免费、开源的分布式版本控制系统它因其速度快、灵活性高和强大的分支管理能力而广受欢迎。分布式版本控制系统中每个开发者都拥有完整的代码仓库包含完整的历史记录。开发者可以在本地进行版本控制操作不需要始终依赖中央服务器。
二、Git安装与全局配置
git的下载:https://git-scm.com/download 我用的redhat系统yum install git -y
1、git的全局配置
[rootredhat GitStudy]# git config --global user.name xiaogang #配置git使用用户
[rootredhat GitStudy]# git config --global user.email 123qq.com #配置git使用邮箱
[rootredhat GitStudy]# git config --global color.ui true #配置语法高亮
[rootredhat GitStudy]# git config --list #列出刚刚配置的内容
user.namexiaogang
user.email123qq.com
color.uitrue
core.repositoryform2、为常用的指令配置别名
1、在用户目录创建.bashrc文件 输入的内容是
#用于输出git提交日志
alias git-loggit log --prettyoneline --all --graph --abbrev-commit3、Git初始化本地代码仓库
[rootredhat ~]# mkdir GitStudy #创建一个空目录
[rootredhat ~]# cd GitStudy/
[rootredhat GitStudy]# git init #初始化git
hint: Using master as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:4、Git的基础命令
Git工作目录下对于文件的修改(增加、删除、更新)会存在几个状态这些修改的状态会随着我们执行Git的命令而发生变化。
常用命令 - git status【文件名或者通配符】 #查看修改的状态- git add #工作区提交项目到暂存区- git commit 【-m 注释信息】 #暂存区提交项目到本地仓库- git log #显示提交到仓库的记录- git push #本地仓库提交项目到远程仓库- git rm #从Git的暂存区域移除文件、在工作区中将被跟踪文件删除- git reset HEAD #取消已经暂存的文件将其转换回未暂存的状态- git reset --hard 3de15d4 #将当前分支的HEAD指向commit哈希值为3de15d4的提交并且重置Staging Area和工作目录将它们恢复到该提交时的状态恢复指定版本 **- git reflog #查看删除的提交记录- git clone #远程仓库拉取到本地仓库- git pull #远程仓库中的代码更新到本地git log命令详解 作用:查看提交记录 命令形式: git log [option] options
–all显示所有分支–prettyoneline将提交信息显示为一行–abbrev-commit使得输出的commitld更简短Ⅰ–graph 以图的形式显示–graph 以图的形式显示 alias git-log‘git log --prettyoneline --all --graph --abbrev-commit’ 上面的配置就是这个意思 在某些情况下有一个文件我不想让他被git管理输入文件名的形式有很麻烦这个时候可以通过在这个仓库创建一个 .gitignore 文件并在里面写上你不需要被管理的文件或者通配符。
三、分支
几乎所有的版本控制系统都以某种形式支持分支。使用分支意味着你可以把你的工作从开发主线上分离开来进行重大的Bug修改、开发新的功能以免影响开发主线。 - git branch #查看本地分支- git branch 分支名 #创建本地分支- git checkout 分支名 #切换分支 加-b参数为创建并切换- git merge 分支名称 #合并分支- git branch -d b1 #删除分支时需要做各种检查- git branch -D b1 #不做任何检查强制删除冲突问题是在两个人修改了同一文件合并到一条线时自己决定咋修改。
四、Git远程仓库
可以借助互联网上提供的一些代码托管服务来实现其中比较常用的有GitHub、码云、GitLab企业常用需要自己搭建等。 1、gitHub (地址: https://github.com/ )是一个面向开源及私有软件项目的托管平台因为只支持Git作为唯一的版本库格式进行托管故名github。 2、码云地址: https://gitee.com/ )是国内的一个代码托管平台由于服务器在国内所以相比于GitHub码云速度会更快。 3、GitLab(地址: https://about.gitlab.com/ )是一个用于仓库管理系统的开源项目使用Git作为代码管理工具并在此基础上搭建起来的web服务一般用于在企业、学校等内部网络搭建git私服。
在这里以码云为例 1、注册码云 2、创建仓库 3、配置ssh公钥 [rootredhat ~]# ssh-keygen -t rsa 然后不断回车 获取公钥[rootredhat ~]# cat ~/.ssh/id_rsa.pub 4、验证是否配置成功 [rootredhat ~]# ssh -T gitgitee.com 好像不要-T也行
1、操作远程仓库
命令: git remote add远端名称仓库路径 。远端名称默认是origin取决于远端服务器设置 。仓库路径从远端服务器获取此URL 。例如: [rootredhat GitStudy]# git remote add origin gitgitee.com:xiao-/git_test.git 【去自己的仓库里获取】 git remote -----查看远程仓库 推送到远程仓库 命令: git push [–set-upstream][远端名称[本地分支名][:远端分支名]] 例如git push origin master
–set-upstream推送到远端的同时并且建立起和远端分支的关联关系。–》git push --set-upstream origin master
如果当前分支已经和远端分支关联则可以省略分支名和远端名。 git push将master分支推送到已关联的远端分支。
[rootredhat GitStudy]# git push --set-upstream origin master 由于在本地和远程仓库建立了分支关系后面只需要git push就行查看本地分支与远程分支之间的关系 ----》 git branch -vv 2、从远程仓库克隆
如果已经有一个远端仓库我们可以直接clone到本地。 命令: git clone仓库路径[本地目录] -----------》本地目录可以省略会自动生成一个目录
3、从远程仓库中抓取和拉取
远程分支和本地的分支一样我们可以进行merge操作只是需要先把远端仓库里的更新都下载到本地再进行操作。
抓取命令: git fetch [remote name] [branch name]抓取指令就是将仓库里的更新都抓取到本地不会进行合并。如果不指定远端名称和分支名则抓取所有分支拉取命令: git pull [remote name] [branch name]拉取指令就是将远端仓库的修改拉到本地并自动进行合并等同于fetchmerge。如果不指定远端名称和分支名则抓取所有并更新当前分支
五、Gitlab sever部署
环境redhat:9
搭建gitlab的时候内存尽量需要大一点内存最好4个G以上 1、安装Gitlab依赖包
yum install -y curl policycoreutils-python-utils openssh-server perl可选下一步安装 Postfix 以发送电子邮件通知
yum install postfix
systemctl start postfix2、添加镜像源 国内使用清华源镜像
[rootlocalhost ~]# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
nameGitlab CE Repository
baseurlhttps://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck0
enabled1
[rootlocalhost ~]# yum makecache3、安装Gitlab
[rootredhat ~]# yum install gitlab-ce
安装历史版本
[rootredhat ~]# yum install -y gitlab-ce-{VERSION} 4、gitlab的配置 [rootredhat ~]# vim /etc/gitlab/gitlab.rb external_url ‘http://gitlab.example.com/’ -----》修改自己的主机 external_url ‘http://192.168.85.128’ #用户访问所使用的URL域名或者IP地址
5、初始化gitlab
[rootredhat ~]# gitlab-ctl reconfigure
第一次使用配置时间较长6、启动gitlab服务
[rootredhat ~]# gitlab-ctl start
[rootredhat ~]# lsof -i:80 ---》可查看80端口有无被占用安装
lsof如果在这个期间出现了“Error executing action run on resource execute[semodule -i /opt/gitlab/”这种selinux的错误。 解决方法是 cd /opt/gitlab/embedded/cookbooks/gitlab/recipes找到selinux.rb文件吧关于gtlab的一些文件注释掉。 详细去看https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/501 7、Gitlab的额外配置 一、gitlab设置https的方式 如果想要以上的https方式正常生效使用则需要把letsencrypt自动生成证书的配置打开这样在执行重新让配置生效命令(gitlab-ctl reconfigure)的时候会自动给域名生成免费的证书并自动在gitlab自带的nginx中加上相关的跳转配置都是全自动的非常方便。
[rootredhat ~]# vim /etc/gitlab/gitlab.rb
letsencrypt[enable] true
letsencrypt[contact_emails] [30423qq.com] #添加联系人的邮件地址二、Gitlab添加smtp邮件功能 前提的安装yum install postfix
gitlab_rails[gitlab_email_enabled] true
gitlab_rails[gitlab_email_from] 309121qq.com #自己的qq邮箱
gitlab_rails[gitlab_email_display_name] gitlab #发送的名字
gitlab_rails[gitlab_email_reply_to] 3090423121qq.com
gitlab_rails[gitlab_email_subject_suffix] [gitlab]
gitlab_rails[smtp_enable] true
gitlab_rails[smtp_address] smtp.qq.com
gitlab_rails[smtp_port] 465
gitlab_rails[smtp_user_name] 3090423121qq.com
gitlab_rails[smtp_password] smtp password -----》#这是qq邮箱的授权码
gitlab_rails[smtp_domain] example.com
gitlab_rails[smtp_authentication] login
gitlab_rails[smtp_enable_starttls_auto] true
gitlab_rails[smtp_tls] true邮箱的授权码获取
期间出现遇到的问题
在这里我出现了第一个问题
There was an error running gitlab-ctl reconfigure: gitlab_rails[smtp_tls] and gitlab_rails[smtp_enable_starttls_auto] are mutually exclusive. Set one of them to false. SMTP providers usually use port 465 for TLS and port 587 for STARTTLS.解决方法 Gitlab 15.10 版本后smtp_enable_starttls_auto 设置为 false 后重启 gitlab 服务.
这里我出现了第二个问题
There was an error running gitlab-ctl reconfigure: letsencrypt_certificate[192.168.85.128] (letsencrypt::http_authorization line 6) had an error: Acme::Client::Error::RejectedIdentifier: acme_certificate[staging] (letsencrypt::http_authorization line 43) had an error: Acme::Client::Error::RejectedIdentifier: Error creating new order :: Cannot issue for 192.168.85.128: The ACME server can not issue a certificate for an IP address解决方法 letsencrypt[‘enable’] false 出现这个问题是我配的https的传输方式所以改成false https的加密传输弄好 发送邮箱测试
[rootredhat ~]# gitlab-rails console
irb(main):004:0 Notify.test_email(3091qq.com,Message Subject,Hello, kazihuo !).deliver_now邮箱测试成功
六、Gitlab使用
在浏览器中输入http://192.168.60.119/然后change password:,并使用root用户登录即可(后续动作根据提示操作)。 1、Gitlab命令行修改密码(重置管理员的密码)
GitLab 版本不同命令会有所不同网上说的而基本都是gitlab-rails console production 推荐大家直接上 GitLab 官网去找对应版本的命令.
[rootredhat ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------Ruby: ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]GitLab: 16.8.0 (16896fceb7a) FOSSGitLab Shell: 14.32.0PostgreSQL: 14.9
------------------------------------------------------------[ booted in 75.66s ]
Loading production environment (Rails 7.0.8)
irb(main):001:0 user User.where(id: 1).first#User id:1 root
irb(main):002:0 user.password 177230637gang17723063738gang
irb(main):003:0 user.password_confirmation 177230637gang #确认密码17723063738gang
irb(main):004:0 user.save!true
(密码必须是8位以上并且有字母数字组合)
账户root
密码自己设置的gitlab-ctl tail ----》 查看日志 搭建成功 docker搭建gitlab https://blog.csdn.net/BThinker/article/details/124097795可以看看别人的博客