手机网站模板用什么做,凡科主要是做什么的,微信做淘宝客网站有哪些,如何做网络集资网站git的工作环境
工作区
暂存区 git add *
版本库 git commit -m “版本描述信息”
HEAD
版本号
版本日志git clone gitIP地址:/自建的目录/自建的库/ #克隆到本地
git add . #存储到暂存区
git commit -m 描述信息 #更新版本
git push origin master …git的工作环境
工作区
暂存区 git add *
版本库 git commit -m “版本描述信息”
HEAD
版本号
版本日志git clone gitIP地址:/自建的目录/自建的库/ #克隆到本地
git add . #存储到暂存区
git commit -m 描述信息 #更新版本
git push origin master #上传到gitlab[rootvm20 ~]# git logcommit fbecfa3d04ae5038aa11bf55942e46c840077ace #id号每个版本都会有一个id号也就是commit id
部署git
环境git-server 192.168.246.214 充当服务器client 192.168.246.213安装所有机器都安装[rootgit-server ~]# yum install -y git[rootgit-server ~]# git --version git version 1.8.3.1所有的机器都添加只要邮箱和用户不一样就可以 # git config --global user.email soho163.com ----设置邮箱# git config --global user.name soho ----加添用户git使用
1.创建一个空目录在中心服务器上创建
[rootgit-server ~]# mkdir /git-test
[rootgit-server ~]# useradd git #创建一个git用户用来运行git
[rootgit-server ~]# passwd git #给用户设置密码
[rootgit-server ~]# cd /git-test/2.通过git init命令把这个目录变成Git可以管理的仓库第1种情况可以改代码还能上传到别人的机器别人也能从你这里下载但是别人不能上传代码到你的机器上。第2种情况只是为了上传代码用别人从这台机器上下载代码也可以上传代码到这台机器上经常用于核心代码库。创建----裸库
语法git init --bare 库名字#在server服务端
[rootgit-server git-test]# git init --bare testgit
Initialized empty Git repository in /git-test/testgit/
[rootgit-server ~]# chown git.git /git-test -R #修改权限
2.仓库创建完成后查看库目录
[rootgit-server git-test]# cd testgit/
[rootgit-server testgit]# ls
branches config description HEAD hooks info objects refs客户端
1.配置免密登录
[rootclient ~]# ssh-keygen #生成秘钥
[rootclient ~]# ssh-copy-id -i git192.168.246.214 #将秘钥传输到git服务器中的git用户
2.克隆git仓库
[rootclient ~]# git clone git192.168.246.214:/git-test/testgit/
Cloning into testgit...
warning: You appear to have cloned an empty repository.
[rootclient ~]# ls #查看仓库已经克隆下来了
anaconda-ks.cfg testgit 创建文件模拟代码提交到仓库
1.在testgit目录下创建一个测试文件test.txt
[rootclient ~]# cd testgit/
[rootclient testgit]# vi test.txt #随便写点东西
2.把文件添加到暂存区使用 git add 建立跟踪
[rootclient testgit]# git add test.txt
注: 这里可以使用 git add * 或者 git add -A
3.提交文件到本地仓库分支
[rootclient testgit]# git commit -m test1
[master (root-commit) 2b51ff9] test11 file changed, 2 insertions()create mode 100644 test.txt-m:描述4.查看git状态[rootclient testgit]# git status
# On branch master #分支位于master
5.修改文件后再此查看状态
[rootclient testgit]# echo 1122334 test.txt
[rootclient testgit]# git status
# 位于分支 master
# 尚未暂存以备提交的变更
# 使用 git add file... 更新要提交的内容
# 使用 git checkout -- file... 丢弃工作区的改动
#
# 修改 readme.txt
#
修改尚未加入提交使用 git add 和/或 git commit
6.先add
[rootclient testgit]# git add -A
8.再次提交commit
[rootclient testgit]# git commit -m add2 test.txt
[master 73bf688] add21 file changed, 1 insertion()[rootclient testgit]# git status
# On branch master
nothing to commit, working directory clean版本回退
查看现在的版本
[rootclient testgit]# git log回到上一个版本
#一个^代表回退一次2个^代表回退2此依此类推……
[rootclient testgit]# git reset --hard HEAD^
HEAD is now at 0126755 test1
2.回到指定的版本(根据版本号):
[rootclient testgit]# git reset --hard dd66ff
HEAD is now at dd66ff9 add2
注消失的ID号可以查看之前的所有的版本
[rootvm20 gittest]# git reflog删除文件
从工作区删除test.txt并且从版本库一起删除
从工作区删除
[rootclient testgit]# rm -rf test.txt
从版本库删除
[rootclient testgit]# git rm test.txt
rm test.txt
[rootclient testgit]# git commit -m 删除文件test.txt
[master cebc081] 删除文件test.txt1 file changed, 3 deletions(-)delete mode 100644 test.txt将代码上传到仓库的master分支
[rootclient testgit]# vi a.txt #创建一个新文件
[rootclient testgit]# git add a.txt
[rootclient testgit]# git commit -m add
[rootclient testgit]# git push origin master #上传到远程仓库master分支
Counting objects: 11, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (11/11), 828 bytes | 0 bytes/s, done.
Total 11 (delta 0), reused 0 (delta 0)
To git192.168.246.214:/git-test/testgit/* [new branch] master - master测试:
在客户端将仓库删除掉然后在克隆下来查看仓库中是否有文件
[rootgit-client ~]# rm -rf testgit/
[rootclient ~]# git clone git192.168.246.214:/git-test/testgit/
Cloning into testgit...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 11 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (11/11), done.
[rootclient ~]# cd testgit/
[rootclient testgit]# ls
a.txt
[rootclient testgit]# cat a.txt
hello world创建分支并合并分支
[rootclient testgit]# ls在客户端操作
[rootclient ~]# git clone git192.168.246.214:/git-test/testgit/
[rootclient testgit]# git status
# On branch master #当前所在为master分支
#
# Initial commit
#
nothing to commit (create/copy files and use git add to track)创建分支:
[rootclient testgit]# git branch dev #创建分支。
[rootclient testgit]# git branch #查看分支。*在哪里就表示当前是哪个分支dev
* master
切换分支:
[rootclient testgit]# git checkout dev
Switched to branch dev
[rootclient testgit]# git branch
* devmaster
在dev分支创建一个文件
[rootclient testgit]# vi test.txt
[rootclient testgit]# git add test.txt
[rootclient testgit]# git commit -m add dev
[dev f855bdf] add dev1 file changed, 1 insertion()create mode 100644 test.txt
现在dev分支的工作完成我们就可以切换回master分支[rootclient testgit]# git checkout master
Switched to branch master切换回master分支后再查看一个test.txt文件刚才添加的内容不见了因为那个提交是在dev分支上而master分支此刻的提交点并没有变
[rootclient testgit]# ls
a.txt现在我们把dev分支的工作成果合并到master分支上
[rootclient testgit]# git merge dev
Updating 40833e0..f855bdf
Fast-forwardtest.txt | 1 1 file changed, 1 insertion()create mode 100644 test.txt
[rootclient testgit]# ls
a.txt test.txt
现在已经将dev分支的内容合并到master上。确认没有问题上传到远程仓库:
[rootclient testgit]# git push origin master合并完成后就可以放心地删除dev分支了
[rootclient testgit]# git branch -d dev
Deleted branch dev (was f855bdf).删除后查看branch就只剩下master分支了
[rootclient testgit]# git branch
* master部署gitlab服务
官网下载gitlab地址
百度搜索gitlab--点击https://gitlab.com/users/sign_in
拉到最下面--点击 关于 GitLab
再拉到最下面--有个Resources--点击Install--往下拉点击有个cenos 7版本的下载--安装命令步骤操作即可配置yum源
[rootgit-server ~]# cd /etc/yum.repos.d/
#配置yum源
[rootgit-server yum.repos.d]# vi gitlab-ce.repo
[gitlab-ce]
nameGitlab CE Repository
baseurlhttps://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever
gpgcheck0
enabled1#安装相关依赖
[rootgit-server yum.repos.d]# yum install -y curl policycoreutils-python openssh-server
[rootgit-server yum.repos.d]# systemctl enable sshd
[rootgit-server yum.repos.d]# systemctl start sshd#安装postfix
[rootgit-server yum.repos.d]# yum install postfix #安装邮箱
[rootgit-server yum.repos.d]# systemctl enable postfix
[rootgit-server yum.repos.d]# systemctl start postfix#安装的版本下面那条命令是安装最新版可能存在不兼容的风险
[rootgit-server yum.repos.d]# yum install -y gitlab-ce-13.1.1-ce.0.el7.x86_64 #安装的版本
[rootgit-server yum.repos.d]# yum install -y gitlab-ce #将会安装gitlab最新版本配置gitlab
[rootgit-server ~]# vim /etc/gitlab/gitlab.rb
1.# 添加对外的域名gitlab.papamk.com请添加A记录指向本服务器的公网IP将原来的修改为
external_url http://192.168.246.214
2.设置地区
gitlab_rails[time_zone] Asia/Shanghai将数据路径的注释去掉可以更改
#第501-505行去除注释
git_data_dirs({default {path /mnt/nfs-01/git-data}
})开启ssh服务:
#第519行去除注释
gitlab_rails[gitlab_shell_ssh_port] 22开启邮箱服务
#直接在637行开始添加以下内容
gitlab_rails[smtp_enable] true #开启smtp服务
gitlab_rails[smtp_address] smtp.163.com #指定smtp地址
gitlab_rails[smtp_port] 465
gitlab_rails[smtp_user_name] xxxx163.com #指定邮箱
gitlab_rails[smtp_password] 邮箱授权密码
gitlab_rails[smtp_domain] 163.com #邮箱地址的域
gitlab_rails[smtp_authentication] login
gitlab_rails[smtp_enable_starttls_auto] true
gitlab_rails[smtp_tls] true
gitlab_rails[smtp_openssl_verify_mode] none
gitlab_rails[gitlab_email_from] xxxx163.com #指定发件邮箱
gitlab_rails[gitlab_email_display_name] Admin #指定发件人
#user[git_user_email] xxxx163.com重置并启动GitLab执行:
[rootgit-server ~]# gitlab-ctl reconfigure #重新加载需要等很长时间启动
[rootgit-server ~]# gitlab-ctl restart #启动邮箱测试
[rootgit-server ~] # gitlab-rails console #进入终端#开始测试
irb(main):001:0 Notify.test_email(xxxxqq.com, Message Subject, Message Body).deliver_now #测试发送邮件是否成功测试web页面访问
输入IP地址直接访问会出来一个界面它默认用户是root直接输入密码就可以设置密码在服务器通过在git客户端
[rootclient ~]# git clone git192.168.246.214:root/testapp.git
Cloning into testapp...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
[rootclient ~]# ls
testapp
[rootclient ~]# cd testapp/
[rootclient testapp]# ls
test.txt 同步时间.txt
[rootclient testapp]#注意:如果克隆不下来可以重新使用命令生成私钥
[rootclient ~]# ssh-keygen -t rsa #然后将公钥添加到gitlab中。使用http的
[rootclient ~]# rm -rf testgit/
[rootclient ~]# git clone http://192.168.246.214/root/testapp.git
Cloning into testapp...
Username for http://192.168.246.214: root
Password for http://root192.168.246.214:12345678 #为自己设置的密码
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
[rootclient ~]# ls
testapp提交到远程gitlab仓库
[rootclient ~]# cd testapp/
[rootclient testapp]# vi update.txt
1000phone
[rootclient testapp]# git add .
[rootclient testapp]# git commit -m updata-test
[rootclient testapp]# git push origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 266 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To git192.168.153.156:root/testapp.git4f35d4b..a0067ea master - masterGitlab 备份与恢复
查看系统版本和软件版本
[rootgit-server ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)[rootgit-server ~]# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
13.1.1数据备份
打开/etc/gitlab/gitlab.rb配置文件查看一个和备份相关的配置项
vim /etc/gitlab/gitlab.rb
gitlab_rails[backup_path] /var/opt/gitlab/backups #备份的路径
gitlab_rails[backup_archive_permissions] 0644 #备份文件的默认权限
gitlab_rails[backup_keep_time] 604800 #保留时长秒为单位# 重启
[rootgit-server ~]# gitlab-ctl reconfigure
或者
[rootgit-server ~]# gitlab-ctl restart# 执行备份命令进行备份
[rootgit-server ~]# /opt/gitlab/bin/gitlab-rake gitlab:backup:create也可以添加到 crontab -e 中定时执行
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create 备份完成会在备份目录中生成一个当天日期的tar包。
[rootgit-server ~]# ls /var/opt/gitlab/backups/
1588774133_2020_05_06_12.10.3_gitlab_backup.tar数据恢复
特别注意
备份目录和gitlab.rb中定义的备份目录必须一致 GitLab的版本和备份文件中的版本必须一致否则还原时会报错
在恢复之前可以删除一个文件以便查看效果
执行恢复操作
[rootgit-server ~]# cd /var/opt/gitlab/backups/
[rootgit-server backups]# gitlab-rake gitlab:backup:restore BACKUP1588774133_2020_05_06_12.10.3
注意恢复文件的名称# 中途会输入2次yes恢复完成后或者重启服务再打开浏览器进行访问发现数据和之前的一致
[rootgit-server backups]# gitlab-ctl restart