版本控制
基本概念—版本库 分布式版本控制
版本库–典型的客户/服务器系统
版本库是版本控制的核心,可以有无限的客户端,客户端通过写数据库分享代码
分布式版本控制:
1集中式版本控制系统
开发者之间共工一个仓库(repository)
所有操作需要联网
常用软件–CVS SVN
2分布式版本控制系统
每一个开发者都是一个仓库的完整克隆
支持断网操作
常用软件:git bitkeeper
目录
git 开源的,分布式版本控制软件
git基础
服务器 安装git 创建服务器版本仓库
客户端 客户端访问方式 客户端命令工具 windows客户端软件
git基本概念
git仓库:保存所有数据的地方
工作区:从仓库中提取文件,在磁盘上使用或修改
暂存区:一个文件,保存下次将要提交的文件列表信息
安装git
[root@xn9 lnmp_soft]# yum -y install git
创建服务器版本控制仓库
[root@xn9 lnmp_soft]# git init /var/git --bare
初始化空的 Git 版本库于 /var/git/
[root@xn9 lnmp_soft]# ls /var/git/
branches config description HEAD hooks info objects refs
客户端访问方式
具体搭建方法请查看
本地访问
git clone file:///var/git
通过远程访问
git clone root@192.168.2.100:/var/git
通过web访问
服务端需要搭建web服务器
git clone http://192.168.2.100/git/
客户端命令工具
clone 将远程服务器仓库克隆到本地
config 修改git配置
add 添加修改文件到暂存区
commit 提交修改到本地仓库
push 提交修改到远程服务器
1.克隆服务器到本地
[root@xn10 html]# git clone root@201.1.2.100:/var/git
正克隆到 'git'...
root@201.1.2.100's password:
warning: 您似乎克隆了一个空版本库。
[root@xn10 html]# cd /var/git
-bash: cd: /var/git: 没有那个文件或目录
[root@xn10 html]# cd git
[root@xn10 git]# ls
2.修改git配置
[root@xn10 git]# git config --global user.email "youxiang@example.com"
[root@xn10 git]# git config --global user.name "nidemingzi"
[root@xn10 git]# cat ~/.gitconfig
[user]
email = youxiang@example.com
name = nidemingzi
3.对数据进行修改
[root@xn10 git]# echo "init date" > init.txt
[root@xn10 git]# mkdir xixi
[root@xn10 git]# cp /etc/hosts xixi/
4.查看仓库数据状态
[root@xn10 git]# git status
# 位于分支 master
#
# 初始提交
#
# 未跟踪的文件:
# (使用 "git add <file>..." 以包含要提交的内容)
#
# init.txt
# xixi/
提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
5.提交修改文件到暂存区
[root@xn10 git]# git add .
6.将暂存区文件提交到本地仓库
git commit -m “注释”
[root@xn10 git]# git commit -m "第一次提交"
[master(根提交) bda590b] 第一次提交
2 files changed, 3 insertions(+)
create mode 100644 init.txt
create mode 100644 xixi/hosts
[root@xn10 git]# git status
# 位于分支 master
无文件要提交,干净的工作区
7.将本地仓库的数据提交到远程服务器
[root@xn10 git]# git config --global push.default simple
[root@xn10 git]# git push
root@201.1.2.100's password:
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 377 bytes | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To root@201.1.2.100:/var/git
* [new branch] master -> master
[root@xn10 git]# git status
# 位于分支 master
无文件要提交,干净的工作区
8.将服务器的数据更新到本地仓库
更新–只下载最新版的数据,确保自己本地数据不是旧数据
[root@xn10 git]# git pull
root@201.1.2.100's password:
Already up-to-date.
[root@xn10 git]# ls
init.txt xixi
9.查看版本日志
]# git log
]# git log --pretty=oneline
]# git log --oneline
]# git reflog
[root@xn10 git]# git log
commit bda590bf3dc537f2ae123d7c5473a381cc6df39d
Author: nidemingzi <youxiang@example.com>
Date: Sat Aug 17 16:22:18 2019 +0800
第一次提交
[root@xn10 git]# git log --pretty=oneline
bda590bf3dc537f2ae123d7c5473a381cc6df39d 第一次提交
[root@xn10 git]# git log --oneline
bda590b 第一次提交
[root@xn10 git]# git reflog
bda590b HEAD@{0}: commit (initial): 第一次提交
[root@xn10 git]#