gitlab基础(1)

1747人浏览 / 0人评论

一、安装git

在centos7系统上,git是默认安装的,可以在命令行输入git --version查看版本。

如果没有请 yum install git -y   #不代表生成环境中

生产环境搭建gitlab:https://blog.csdn.net/weixin_44224288/article/details/90927464

二、git配置

[root@git-01 ~]# git config
usage: git config [options]

Config file location
    --global              使用全局配置文件
    --system             使用系统级配置文件
    --local                 使用版本库级配置文件

(1)配置信息

[root@git-01 ~]# git config --global user.name "liangzeyu"
配置git的使用用户

[root@git-01 ~]# git config --global user.email "2249902650@qq.com"
配置git使用的邮箱

[root@git-01 ~]# git config --global color.ui true
使用语法高亮

 [root@git-01 ~]# git config --list
user.name=liangzeyu
user.email=2249902650@qq.com
color.ui=true

 [root@git-01 ~]# cat .gitconfig 
[user]
    name = liangzeyu
    email = 2249902650@qq.com
[color]
    ui = true

三、git初始化

 初始化工作目录,对已存在的目录都可以初始化

root@git-01 ~]# mkdir /server/git_data -p
[root@git-01 ~]# cd /server/git_data/
[root@git-01 git_data]# git init
Initialized empty Git repository in /server/git_data/.git/
 

查看状态

[root@git-01 git_data]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
 

 

隐藏.git目录介绍

 

branches  #分支目录

config       #定义项目特有的配置选项

description #仅供git web程序使用

HEAD         #指示当前的分支

hooks        #包含git钩子文件

objects       #存放所有数据内容,有info和pack俩个子文件夹

refs              #存放执行数据(分支)的提交对象的指针

index         #保存暂存区信息。在执行git init的时候,这个文件还没有

四、git常规使用

(1)git基础命令

[root@git-01 git_data]# git status
# On branch master        位于分支master
#
# Initial commit                初始提交
#
nothing to commit (create/copy files and use "git add" to track)  无文件提交(创建/拷贝文件并使用“git add”建立追踪)
 

创建文件,查看git

提交文件

a文件在index的暂存区

git add .   #使用git add .或者*可以把所有改动过的文件都提交一遍

git rm --cached 1    #将文件撤出暂存区

(2)提交本地仓库

[root@git-01 git_data]# git commit -m "commit 2"
(3)修改文件名

mv 2 a

[root@git-01 git_data]# git rm --cached 2   #从暂存区删除文件2

 

提交到本地仓库

[root@git-01 git_data]# git commit -m "commit a"
 

方法2:

使用 git mv 2 a   

[root@git-01 git_data]# git commit -m "rename 2 a "
完成改名

 

五、查看文件内容不同 diff

 
比对的是暂存区和本地仓库文件的不同处

[root@git-01 git_data]# git commit -m "modified a"   #提交后在比对则暂存区和本地仓库内容相同

[root@git-01 git_data]# git diff  --cached a
 

六、git log 查看历史git commit快照操作

[root@git-01 git_data]# git log
commit 54b1c916e22e157c0e900702ef7b57e45323a96b    ##哈希值
Author: liangzeyu <2249902650@qq.com>                          ##作者个人信息
Date:   Fri Jun 19 22:55:06 2020 +0800                                ##时间

    rename 2 a                                                                                 ##-m  个人写的提交信息

commit c350ddff03b0e36d49d8fd325b380f168c2bb77c
Author: liangzeyu <2249902650@qq.com>
Date:   Fri Jun 19 22:53:27 2020 +0800
 

[root@git-01 git_data]# git log --oneline      ##一行简单的显示
54b1c91 rename 2 a
c350ddf commit 2
62efaf1 commit a
bfeaae3 commit 2
 

[root@git-01 git_data]# git log --oneline --decorate    ##显示当前指针向哪里
54b1c91 (HEAD, master) rename 2 a
c350ddf commit 2
62efaf1 commit a
bfeaae3 commit 2
 

[root@git-01 git_data]# git log -p     #显示具体内容的变化

[root@git-01 git_data]# git log -1     #只显示1条内容

七、恢复数据

1、

修改了a文件

[root@git-01 git_data]# git checkout -- a 
[root@git-01 git_data]# cat a

2、

3、

可以使用指针来恢复

[root@git git_data]# git log ‐‐oneline
59ba2a9 add ccc
dbead4c add bbb
4c57a60 modified a
5692532 rename a.txt a
7adfca0 commit a.txt
b4017a8 commit a
`Git服务程序中有一个叫做HEAD的版本指针,当用户申请还原数据时,其实就是将HEAD指针指向到某个特定的提交
版本,但是因为Git是分布式 版本控制系统,为了避免历史记录冲突,故使用了SHA‐1计算出十六进制的哈希字串
来区分每个提交版本,另外默认的HEAD版本指针会指向到最近的一次提交版本记录`
[root@git git_data]# git reset ‐‐hard 4c57a60
HEAD 现在位于 4c57a60 modified a
`刚刚的操作实际上就是改变了一下HEAD版本指针的位置,就是你将HEAD指针放在那里,那么你的当前工作版本就
会定位在那里,要想把内容再还原到最新提交的版本,先看查看下提交版本号

全部评论