gitlab

Gitlab

安装git

yum安装

[root@git ~]# yum -y install git

编译安装 

#安装依赖关系
[root@git ~]# yum install curl-devel expat-devel gettext-devel  openssl-devel zlib-devel autoconf gcc perl-ExtUtils-MakeMaker
# 编译安装 
[root@git ~]# tar -zxf git-2.0.0.tar.gz
[root@git ~]# cd git-2.0.0
[root@git ~]# ./configure --prefix=/usr/local/git # 没有文件可以略过
[root@git ~]# make  
[root@git ~]# make install  

初次运行git前的配置 

git config --global user.name “username” #配置git使用用户
git config --global user.email “email@mail.com” #配置git使用邮箱
git config --global color.ui true #语法高亮
git config --list # 查看全局配置

 

[root@git ~]# git config --global user.name 'zhang'
[root@git ~]# git config --global user.email 'zhang@qq.com'
[root@git ~]# git config --global color.ui true
[root@git ~]# git config --list
user.name=zhang
user.email=zhang@qq.com
color.ui=true

 查看配置文件


[root@git ~]# cat .gitconfig 
[user]
        name = zhang
        email = zhang@qq.com
[color]
        ui = true

创建裸库 

[root@git ~]# mkdir /git
[root@git ~]# cd /git
[root@git git]# git init --bare zx.git
初始化空的 Git 版本库于 /git/zx.git/

创建本地库 

[root@master2 ~]# git clone 192.168.20.143:/git/zx.git
warning: 您似乎克隆了一个空版本库。
[root@master2 ~]# cd zx
[root@master2 zx]# ls
[root@master2 zx]# vim test.sh
[root@master2 zx]# cat test.sh 
#!/bin/bash
echo '111'

 

[root@master2 zx]# git add .   
[root@master2 zx]# git commit -m 'first'
[master(根提交) a962c49] first
 1 file changed, 2 insertions(+)
 create mode 100644 test.sh
[root@master2 zx]# git push origin master
root@192.168.20.143's password: 
Counting objects: 3, done.
Writing objects: 100% (3/3), 218 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.20.143:/git/zx.git
 * [new branch]      master -> master

git add .
git commit -m ‘名字’
git push origin master

 

Git常规命令 

创建文件
[root@master2 zx]# touch file
[root@master2 zx]# git status
# 位于分支 master
# 未跟踪的文件:
#   (使用 "git add <file>..." 以包含要提交的内容)
#
#       file
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)

 将文件提交到暂存区

[root@master2 zx]# git add .

文件会添加到.git隐藏目录 

[root@master2 zx]# ls -a
.  ..  file  .git  test.sh
[root@master2 zx]# cd .git
[root@master2 .git]# tree
.
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       ├── heads
│       │   └── master
│       └── remotes
│           └── origin
│               └── master
├── objects
│   ├── 0b
│   │   └── 3f6f232c1737c7afd609b86e4e7e1986e3c815
│   ├── 48
│   │   └── 384f93f82b20c38a6f18bae65555f3236d8bcb
│   ├── a9
│   │   └── 62c4988e3627c5314da76228de2d31cf0d8ea6
│   ├── e6
│   │   └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│   ├── info
│   └── pack
└── refs
    ├── heads
    │   └── master
    ├── remotes
    │   └── origin
    │       └── master
    └── tags

从工作区提交到本地仓库 

[root@master2 zx]# git commit -m 'first commit'
[master b64424d] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file
 [root@master2 zx]# git status
# 位于分支 master
# 您的分支领先 'origin/master' 共 1 个提交。
#   (使用 "git push" 来发布您的本地提交)
#
无文件要提交,干净的工作区

 git commit -a -m “注释信息”

删除git内的文件 

• 没有添加到暂存区的数据直接rm删除即可。

• 已经添加到暂存区数据:

git rm --cached database

#→将文件从git暂存区域的追踪列表移除(并不会删除当前工作目录内的数据文件)

git rm -f database

[root@master2 zx]# git rm --cached 123
rm '123  # 将文件从暂存区删除,不删除源文件
[root@master2 zx]# git add 123
[root@master2 zx]# git rm -f 123 # 将文件从暂存区删除,删除源文件,文件不在暂存区内无法删除
rm '123'

查看历史记录 

[root@master2 zx]# git log
commit 3e3834e8ad57e995b90a9fc2f63cdf85e034c3ae
Author: xiao <xiao@qq.com>
Date:   Tue Nov 21 23:52:29 2023 +0800

    444

commit 55b615cb4a8dfe5facf61fe56f965712a8361771
Author: xiao <xiao@qq.com>
Date:   Tue Nov 21 23:51:38 2023 +0800

    333

commit b64424d42fe5f0890b6b54531203791f533d7ecd
Author: xiao <xiao@qq.com>
Date:   Tue Nov 21 23:40:37 2023 +0800

    first commit

还原历史数据 

[root@master2 zx]# git reset --hard b64424d42
HEAD 现在位于 b64424d first commit
[root@master2 zx]# ls
file  test.sh

 还原未来数据

[root@master2 zx]# git reflog
b64424d HEAD@{0}: reset: moving to b644
3e3834e HEAD@{1}: commit: 444
55b615c HEAD@{2}: commit: 333
b64424d HEAD@{3}: commit: first commit
a962c49 HEAD@{4}: commit (initial): fir
[root@master2 zx]# 
[root@master2 zx]# git reset --hard 3e3834e
HEAD 现在位于 3e3834e 444
[root@master2 zx]# ls
123  444  file  test.sh

分支情况 

 

git branch newrain 添加分支
git branch 查看分支
git checkout newrain 切换分支
git branch -d newrain 删除分支 

[root@master2 zx]# git branch
* master
[root@master2 zx]# git branch newrain
[root@master2 zx]# git branch
* master
  newrain
  [root@master2 zx]# git branch  -d newrain
已删除分支 newrain(曾为 3e3834e)。

gitlab安装配置 

安装gitlab

# 安装依赖,并启动ssh、防火墙开启相应端口、postfix
[root@git ~]# yum install -y curl policycoreutils-python openssh-server perl

# 上传安装包
[root@git ~]# rz
[root@git ~]# yum -y install gitlab-jh-16.5.2-jh.0.el7.x86_64.rpm 
# 安装完成后会直接启动
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.20.134'
[root@gitlab ~]# gitlab-ctl reconfigure
[root@gitlab ~]#  gitlab-ctl status
run: gitaly: (pid 4491) 48s; run: log: (pid 4087) 279s
run: gitlab-monitor: (pid 4539) 44s; run: log: (pid 4251) 207s
run: gitlab-workhorse: (pid 4501) 47s; run: log: (pid 4099) 273s
run: logrotate: (pid 4125) 265s; run: log: (pid 4124) 265s
run: nginx: (pid 4112) 271s; run: log: (pid 4111) 271s
run: node-exporter: (pid 4175) 243s; run: log: (pid 4174) 243s
run: postgres-exporter: (pid 4528) 45s; run: log: (pid 4223) 219s
run: postgresql: (pid 3933) 343s; run: log: (pid 3932) 343s
run: prometheus: (pid 4514) 46s; run: log: (pid 4156) 259s
run: redis: (pid 3876) 355s; run: log: (pid 3875) 355s
run: redis-exporter: (pid 4186) 237s; run: log: (pid 4185) 237s
run: sidekiq: (pid 4078) 281s; run: log: (pid 4077) 281s
run: unicorn: (pid 4047) 287s; run: log: (pid 4046) 287s
[root@gitlab ~]# netstat -lntup|grep 80
tcp        0      0 127.0.0.1:8080      0.0.0.0:*    LISTEN     4073/unicorn master 
tcp        0      0 0.0.0.0:80      0.0.0.0:*         LISTEN      4112/nginx: master  
tcp        0      0 0.0.0.0:8060       0.0.0.0:*      LISTEN      4112/nginx: master  

 登陆 Gitlab
用户名: root 密码存放在 /etc/gitlab/initial_root_password 文件中,该文件会在24小时后删除

  

创建用户 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值