欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

git多人开发流程

程序员文章站 2024-01-24 20:24:16
...

一、环境介绍

服务器角色			IP地址
git服务端			192.168.1.107
git客户端1			192.168.1.108
git客户端2			192.168.1.109

1.git命令使用注意事项1

git clone aaa@qq.com:这里是仓库在系统上的绝对路径

2.1.git命令使用注意事项2

#这是将/data/base1 仓库下的内容克隆到当前目录下
git clone aaa@qq.com:/data/base1 ./

#这是将base1这个目录以及它下边的内容克隆到当前目录下
git clone aaa@qq.com:/data/base1

二、多人协同开发流程

1.在服务端创建仓库并且初始化

[aaa@qq.com ~]# mkdir /data
[aaa@qq.com ~]# cd /data/
[aaa@qq.com data]# mkdir base1
[aaa@qq.com data]# git init --bare base1/
Initialized empty Git repository in /data/base1/
    
#修改/data/base1的权限,否则客户端不能将数据提交到仓库中
[aaa@qq.com ~]# chown -R test1:test1 /data/base1/

2.在客户端1克隆仓库

[aaa@qq.com data]# git clone aaa@qq.com:/data/base1 ./
Cloning into '.'...
aaa@qq.com's password:  #输入test1的密码
warning: You appear to have cloned an empty repository.
[aaa@qq.com data]# ls
[aaa@qq.com data]# ls -a
.  ..  .git

3.在客户端1中添加数据 并提交到远程仓库

[aaa@qq.com ~]# cd /data/
[aaa@qq.com data]# touch test1_1
[aaa@qq.com data]# git add test1_1
[aaa@qq.com data]# git commit -m '1'
[master (root-commit) 8090303] 1
 1 file changed, 1 insertion(+)
 create mode 100644 test1_1
 
 #将数据提交到远程仓库
 [aaa@qq.com data]# git push origin master
aaa@qq.com's password: 
Counting objects: 3, done.
Writing objects: 100% (3/3), 211 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To aaa@qq.com:/data/base1
 * [new branch]      master -> master

此时客户端1完成了开发工作,并且提交了数据

4.此时客户端2参加到了工作当中

#在客户端2克隆仓库,并且提交数据
[aaa@qq.com ~]# git clone aaa@qq.com:/data/base1 ./
Cloning into 'base1'...
aaa@qq.com's password:  #输入test1的密码
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

#添加新数据 并且提交到远程仓库
[aaa@qq.com data]# touch test2_1
[aaa@qq.com data]# vim test2_1 
[aaa@qq.com data]# git add test2_1
[aaa@qq.com data]# git commit -m '1'
[master f7708f1] 1
 1 file changed, 1 insertion(+)
 create mode 100644 test2_1
 
[aaa@qq.com data]# git push origin master
aaa@qq.com's password: 
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 259 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To aaa@qq.com:/data/base1/
   8090303..f7708f1  master -> master


5.此时客户端1还在继续开发

[aaa@qq.com data]# ls
test1_1
[aaa@qq.com data]# touch test1_2
[aaa@qq.com data]# touch add test1_2
[aaa@qq.com data]# git add -A
[aaa@qq.com data]# git commit -m '2'
[master f2f9707] 2
 2 files changed, 1 insertion(+)
 create mode 100644 add
 create mode 100644 test1_2
 
 #我们发现将数据提交到远程仓库的时候开始报错了
 [aaa@qq.com data]# git push origin master
aaa@qq.com's password: 


git多人开发流程

这是因为客户端2在客户端1提交之前 已经提交了最新版本,客户端1是在第一版本的基础上进行提交的,所以版本和客户端2提交的冲突了。

6.在客户端1拉取最新版本 然后在提交

#先拉取最新版本
[aaa@qq.com data]# git pull
aaa@qq.com's password: 

[aaa@qq.com data]# ls
test1_1  test1_2  test2_1

[aaa@qq.com data]# git push origin master
aaa@qq.com's password: 
Counting objects: 8, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 554 bytes | 0 bytes/s, done.
Total 6 (delta 1), reused 0 (delta 0)
To aaa@qq.com:/data/base1
   f7708f1..7405a1a  master -> master


总结:在提交数据之前 一定要先pull 将版本获取到最新,在提交数据到远程仓库

相关标签: liunx