1.git试验环境安装
操作系统centos 7.3,使用的docker 安装
docker run --name gitlab-postgresql -d \
--env 'DB_NAME=gitlabhq_production' \
--env 'DB_USER=gitlab' --env 'DB_PASS=password' \
sameersbn/postgresql:9.4-12
docker run --name gitlab-redis -d sameersbn/redis:latest
docker run --name gitlab -d \
--link gitlab-postgresql:postgresql --link gitlab-redis:redisio \
--publish 10022:22 --publish 10080:80 \
--env 'GITLAB_PORT=10080' --env 'GITLAB_SSH_PORT=10022' \
--env 'GITLAB_SECRETS_DB_KEY_BASE=long-and-random-alpha-numeric-string' \
-v /_gitlab/data:/home/git/data \
-v /_gitlab/log:/home/git/log \
sameersbn/gitlab:8.4.4
2.git的基本结构
引用了网上的一张图,这张图清晰表达git的架构。workspace是工作区,可以用编辑器直接编辑其中的文件;Index/Stage是暂存区,编辑后的文件可以添加到(add)暂存区;Repository是本地库,暂存区的文件提交(commit)到本地库,本地库中文件可以检出(checkout)到工作空间;Remote是远程仓库,本地仓库的变化可以push到远程仓库,远程仓库用于多人共享。
3.git实验
1)建立1个组gitdemo, 4个用户,scm(配置管理)、ci01(持续集成)、dev01(开发人员1)和dev02(开发人员2)。
2)用ssh-keygen为每一用户生成ssh key,在gitlab上创建对应的4个用户,并配置ssh key 免密码登录。
3)scm用户登录gitlab,创建一个新的工程,创建完后,通过界面可查询到这个工程。gitlab是远程仓库。
4)scm用户登录操作系统,克隆远程仓库到本地仓库,因为在同一台机器上,用的是ssh://git@localhost:10022/GitDemo/gitflowdemo如果不在同一台机器上,localhost替换为实际的ip地址或域名。
[scm@gitserver myproject]$ git clone ssh://git@localhost:10022/GitDemo/gitflowdemo.git
正克隆到 'gitflowdemo'...
The authenticity of host '[localhost]:10022 ([::1]:10022)' can't be established.
ECDSA key fingerprint is 85:c8:4d:1d:a0:25:f5:a6:95:7e:68:0a:ed:04:50:98.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:10022' (ECDSA) to the list of known hosts.
warning: 您似乎克隆了一个空版本库。
[scm@gitserver myproject]$ ls
demo gitflowdemo
[scm@gitserver myproject]$ cd gitflowdemo
[scm@gitserver gitflowdemo]$ ls
[scm@gitserver gitflowdemo]$
编辑.gitignore
.gitignore
*.out
*.o
bin
编辑hello.c文件
#include<stdlib.h>
#include<stdio.h>
int main(int arg, char* argv[]){
printf("inited by SCM.\n");
}
将工作区的文件添加到暂存区、添加到本地仓库、push到远程仓库。
[scm@gitserver gitflowdemo]$ git config --global user.name "Administrator"
[scm@gitserver gitflowdemo]$ git config --global user.email "admin@example.com"
[scm@gitserver gitflowdemo]$ git add .
[scm@gitserver gitflowdemo]$ git commit -m 'init'
[master(根提交) c4d