Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。 Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。
构建git本地仓库,并测试可用性。
-centos7 -git
安装git服务:
[root@controller ~]# yum -y install git创建git工作目录:
[root@controller ~]# mkdir test_git创建项目git_project,并初始化仓库:
[root@controller ~]# cd test_git/ [root@controller test_git]# git init --bare git_project Initialized empty Git repository in /root/test_git/git_project/ [root@controller test_git]# cd git_project/ [root@controller git_project]# git init Initialized empty Git repository in /root/test_git/git_project/.git/将当前目录内容添加到缓存区:
[root@controller git_project]# pwd /root/test_git/git_project [root@controller git_project]# echo "test_git" > readme.txt [root@controller git_project]# git add .设置git用户:
[root@controller git_project]# git config --global user.email "you@example.com" [root@controller git_project]# git config --global user.name "Your Name"将改动提交到本地仓库:
格式:git commit -m “本次提交的说明”
[root@controller git_project]# git commit -m "test_git" [master (root-commit) 082e956] test_git 14 files changed, 510 insertions(+) create mode 100644 HEAD create mode 100644 config create mode 100644 description create mode 100755 hooks/applypatch-msg.sample create mode 100755 hooks/commit-msg.sample create mode 100755 hooks/post-update.sample create mode 100755 hooks/pre-applypatch.sample create mode 100755 hooks/pre-commit.sample create mode 100644 hooks/pre-push.sample create mode 100755 hooks/pre-rebase.sample create mode 100755 hooks/prepare-commit-msg.sample create mode 100755 hooks/update.sample create mode 100644 info/exclude create mode 100644 readme.txt查看所有提交:
[root@controller git_project]# git log commit 082e956478fc4476d2e90f3ab179cc94425e53e1 Author: Your Name <you@example.com> Date: Wed May 22 04:21:54 2019 -0400 test_git检验本地仓库能否正常运行,需要将本地仓库添加为远程仓库,并进行拉取测试。
添加本地仓库为远程仓库:
添加origin远程仓库,地址为本机git_project项目下的仓库
[root@controller git_project]# git remote add origin 192.168.100.20:/root/test_git/git_project/将本地库的内容提交到远程库:
格式:git push <远程主机名> <本地分支名> <远程分支名>,远程分支名被省略时,则根据追踪关系推送同名分支或者新建分支并推送。
[root@controller git_project]# git push origin master The authenticity of host '192.168.100.20 (192.168.100.20)' can't be established. ECDSA key fingerprint is f2:e8:0f:d6:bf:c8:e1:70:0d:d1:8a:47:15:4a:41:7e. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.100.20' (ECDSA) to the list of known hosts. root@192.168.100.20's password: Everything up-to-date从远程仓库拉取:
[root@controller ~]# mkdir test [root@controller ~]# cd test [root@controller test]# git clone 192.168.100.20:/root/test_git/git_project/ Cloning into 'git_project'... root@192.168.100.20's password: remote: Counting objects: 18, done. remote: Compressing objects: 100% (15/15), done. remote: Total 18 (delta 1), reused 0 (delta 0) Receiving objects: 100% (18/18), 7.39 KiB | 0 bytes/s, done. Resolving deltas: 100% (1/1), done.成功。