版权声明:作者-傲娇天子 博文主页地址:https://blog.csdn.net/qq_41116956 欢迎转载,转载请在文章页面明显位置给出原文链接,谢谢 https://blog.csdn.net/qq_41116956/article/details/84061962
安装
服务器ip:192.168.1.65
客户端ip:192.168.1.195
- 服务器:
[root@www ~]# yum install -y git
......
更新完毕:
git.x86_64 0:1.8.3.1-14.el7_5
作为依赖被升级:
perl-Git.noarch 0:1.8.3.1-14.el7_5
完毕!
设置git基本配置
[root@www ~]# git config --global user.name "Linux Git"
[root@www ~]# git config --global user.email "[email protected]"
[root@www etc]# git config --global core.editor vim
查询服务器Git的信息:
[root@www Gitbase.git]# git config --list
user.name=Linux Git
[email protected]
core.editor=vim
- 客户端和服务器类似:
[root@CactiEZ ~]# yum install -y git
......
更新完毕:
git.x86_64 0:1.8.3.1-14.el7_5
作为依赖被升级:
perl-Git.noarch 0:1.8.3.1-14.el7_5
完毕!
[root@CactiEZ ~]# git config --global user.name "客户端Git"
[root@CactiEZ ~]# git config --global user.email "客户端@youxian.com"
[root@CactiEZ ~]# git config --global core.editor vim
[root@CactiEZ ~]# git config --list
user.name=客户端Git
user.email=客户端@youxian.com
core.editor=vim
部署
- 服务器部署
创建Git版本仓库并初始化文本,以.git为后缀:
[root@www ~]# mkdir Gitbase.git
[root@www ~]# cd Gitbase.git/
[root@www Gitbase.git]# git --bare init
初始化空的 Git 版本库于 /root/Gitbase.git/
[root@www Gitbase.git]# ls
branches config description HEAD hooks info objects refs
加上.git后初始化后会有相应的文件
服务器部署完成!
- 客户端部署
客户端需要从Git服务器下拉/推送数据,需要Git协议支持,如http/https/ssh,这里选用ssh协议
设置Git客户机免密登陆服务器
[root@CactiEZ ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
e8:10:64:43:ce:3e:d9:03:5c:c5:40:e2:f2:f1:29:3e [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .*.++. |
| B + . |
| . O |
| + B o |
| B * S |
| . = . |
| E . |
| . |
| |
+-----------------+
[root@CactiEZ ~]# ssh-copy-id 192.168.1.65
[email protected]'s password:
Now try logging into the machine, with "ssh '192.168.1.65'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
在本地下拉Git服务器数据库(下拉的文件名称为Gitbase没有.git后缀,并且下拉的文件中没有数据):
[root@CactiEZ ~]# git clone 192.168.1.65:/root/Gitbase.git
[root@CactiEZ ~]# ls
... Gitbase
1:创建文件并提交到本地Git数据库:
[root@CactiEZ ~]#
[root@CactiEZ ~]# cd Gitbase/
[root@CactiEZ Gitbase]# ls
[root@CactiEZ Gitbase]# touch 1.txt
[root@CactiEZ Gitbase]# ls
1.txt
[root@CactiEZ Gitbase]# git add 1.txt
[root@CactiEZ Gitbase]# git status
[root@CactiEZ Gitbase]# git commit -m "提交客户端数据"
2:提交到Git服务器
定义Git服务器
[root@CactiEZ Gitbase]# git remote add server 192.168.1.65:/root/Gitbase.git
提交到Git服务器
[root@CactiEZ Gitbase]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 229 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.1.65:/root/Gitbase.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
这里已经提交到服务器了
奇怪的是,小博主在Git服务器中查询提交的文件既然没有,因此多了些问号????
为了验证文件是否提交到服务器,小博主准备在一个全新的空文件中,重新下拉Git服务器的文件
[root@CactiEZ 1]# ls
[root@CactiEZ 1]# git clone 192.168.1.65:/root/Gitbase.git
Initialized empty Git repository in /root/1/Gitbase/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@CactiEZ 1]# ls
Gitbase
[root@CactiEZ 1]# cd Gitbase/
[root@CactiEZ Gitbase]# ls
1.txt
验证结果,文件存在,也就是说,文件是提交成功了的,针对这个问题,小博主以后了解后分享给大家
END!