远程版本库

(1)创建一个裸版本库

[root@localhost tmp]# git init fluff2
Initialized empty Git repository in /tmp/fluff2/.git/
[root@localhost tmp]# ls
fluff2
[root@localhost tmp]# git init --bare fluff
Initialized empty Git repository in /tmp/fluff/
[root@localhost tmp]# ls
fluff fluff2

(2)远程版本库

Git使用远程版本库和远程追踪分支来引用另一个版本库,并有助于与该版本库建立连接。

常见命令:

  • git fetch 从远程版本库抓取对象及其相关的元数据
  • git pull 跟fetch类似,但合并修改到相应本地分支
  • git push 转移对象及其相关的元数据到远程版本库
  • git ls-remote 显示一个给定的远程版本库的引用列表

分支类别:

  • 远程追踪分支与远程版本库相关联,专门用来追踪远程版本库中每个分支的变化。
  • 本地追踪分支与远程追踪分支相配对。它是一种集成分支,用于收集本地开发和远程追踪分支中的变更。
  • 任何本地的非追踪分支通常称为特性或开发分支。
  • 为了完成命名空间,远程分支是一个设在非本地的远程版本库的分支。

示例:

创建权威版本库public_html.git

用一个初始版本库填充Depot

[root@localhost tmp]# cd Depot/
[root@localhost Depot]# git clone --bare /root/public_html public_html.git
Initialized empty Git repository in /tmp/Depot/public_html.git/
[root@localhost Depot]# ls
public_html.git [root@localhost Depot]# cd /root/public_html/
[root@localhost public_html]# ls #有工作目录
foo.html index.html yes.html
[root@localhost public_html]# ls -aF
./ ../ foo.html .git/ index.html yes.html
[root@localhost public_html]# ls -aF .git
./ BISECT_ANCESTORS_OK BISECT_NAMES branches/ config HEAD index logs/ ORIG_HEAD
../ BISECT_LOG BISECT_START COMMIT_EDITMSG description hooks/ info/ objects/ refs/
[root@localhost public_html]# cd /tmp/Depot/
[root@localhost Depot]# ls -aF public_html.git/ #没有工作目录
./ ../ branches/ config description HEAD hooks/ info/ objects/ packed-refs refs/ [root@localhost Depot]# cd public_html.git/
[root@localhost public_html.git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = true

因为在克隆过程中使用了--bare选项,所以Git没有引入一般默认的origin远程版本库。

制作自己的origin远程版本库

[root@localhost public_html.git]# cd /root/public_html/
[root@localhost public_html]# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[root@localhost public_html]# git remote add origin /tmp/Depot/public_html
[root@localhost public_html]# cat .git/config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = /tmp/Depot/public_html
fetch = +refs/heads/*:refs/remotes/origin/*

在远程版本库中建立新的远程追踪分支,代表来自远程版本库的分支,以完成建立origin远程版本库进程

[root@localhost public_html]# git branch -a
* master
newtest
testing
[root@localhost public_html]# git remote update
Fetching origin
From /tmp/Depot/public_html
* [new branch] master -> origin/master
* [new branch] newtest -> origin/newtest
* [new branch] testing -> origin/testing
[root@localhost public_html]# git branch -a
* master
newtest
testing
remotes/origin/master #远程追踪分支:掌握和跟踪远程版本苦苦master分支中的提交
remotes/origin/newtest
remotes/origin/testing

在版本库中进行开发

[root@localhost public_html]# git show-branch -a
* [master] add test.txt
! [newtest] newtest yes
! [testing] newtest yes
! [origin/master] add test.txt
! [origin/newtest] newtest yes
! [origin/testing] newtest yes
------
++ ++ [newtest] newtest yes
++ ++ [newtest^] removed test.txt
*+++++ [master] add test.txt
[root@localhost public_html]# vim fuzzy.txt
[root@localhost public_html]# cat fuzzy.txt
Fuzzy Wuzzy was a bear
Fuzzy Wuzzy had no hair
Fuzzy Wuzzy wasn't very fuzzy,
Was he?
[root@localhost public_html]# git add fuzzy.txt
[root@localhost public_html]# git commit -m "add fuzzy"
[master 5571b42] add fuzzy
1 files changed, 4 insertions(+), 0 deletions(-)
create mode 100644 fuzzy.txt
[root@localhost public_html]# git show-branch -a
* [master] add fuzzy
! [newtest] newtest yes
! [testing] newtest yes
! [origin/master] add test.txt
! [origin/newtest] newtest yes
! [origin/testing] newtest yes
------
* [master] add fuzzy
++ ++ [newtest] newtest yes
++ ++ [newtest^] removed test.txt
*+++++ [origin/master] add test.txt

推送变更

[root@localhost public_html]# git push origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 362 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/Depot/public_html
b0b257c..5571b42 master -> master

Git提取master分支的变更,将它们捆绑在一起,发送到名为origin的远程版本库中。

探测远程版本库并验证是否更新

在本地
[root@localhost public_html]# cd /tmp/Depot/public_html.git/
[root@localhost public_html.git]# git show-branch
! [master] add fuzzy
* [newtest] newtest yes
! [testing] newtest yes
---
+ [master] add fuzzy
*+ [newtest] newtest yes
*+ [newtest^] removed test.txt
+*+ [master^] add test.txt 在不同物理机
[root@localhost public_html.git]# git ls-remote origin
然后用git rev-parse HEAD或git show ID来展示那些与当前本地分支匹配的提交ID

添加新的开发人员

[root@localhost tmp]# mkdir bobo
[root@localhost tmp]# ls
bobo Depot fluff fluff2
[root@localhost tmp]# cd bobo/
[root@localhost bobo]# ls
[root@localhost bobo]# git clone /tmp/Depot/public_html.git
Initialized empty Git repository in /tmp/bobo/public_html/.git/
[root@localhost bobo]# ls
public_html
[root@localhost bobo]# cd public_html/
[root@localhost public_html]# ls #这里因为这前建立origin时原版本库在newtest分支上
foo.html index.html yes.html
[root@localhost public_html]# git branch
* newtest
[root@localhost public_html]# ls -aF
./ ../ foo.html .git/ index.html yes.html
[root@localhost public_html]# cd .git/
[root@localhost .git]# ls
branches config description HEAD hooks index info logs objects packed-refs refs
[root@localhost .git]# cat config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = /tmp/Depot/public_html.git
[branch "newtest"] #此时有一个默认的远程版本库
remote = origin
merge = refs/heads/newtest
[root@localhost .git]# git remote show origin
* remote origin
Fetch URL: /tmp/Depot/public_html.git
Push URL: /tmp/Depot/public_html.git
HEAD branch (remote HEAD is ambiguous, may be one of the following):
newtest
testing
Remote branches:
master tracked
newtest tracked
testing tracked
Local branch configured for 'git pull':
newtest merges with remote newtest
Local ref configured for 'git push':
newtest pushes to newtest (up to date) [root@localhost public_html]# git branch -a
* newtest
remotes/origin/HEAD -> origin/newtest #远程版本库认为的活动分支
remotes/origin/master
remotes/origin/newtest
remotes/origin/testing

修改提交,推送到仓库中的主版本库

[root@localhost public_html]# cat yes.html
AAAAAA
[root@localhost public_html]# vim yes.html
[root@localhost public_html]# cat yes.html
BBBBBBB [root@localhost public_html]# git diff
diff --git a/yes.html b/yes.html
index b068058..6a4ca1b 100644
--- a/yes.html
+++ b/yes.html
@@ -1 +1 @@
-AAAAAA
+BBBBBBB
[root@localhost public_html]# git commit yes.html
[newtest c24a693] change yes.html
1 files changed, 1 insertions(+), 1 deletions(-) [root@localhost public_html]# git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 253 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /tmp/Depot/public_html.git
b488b19..c24a693 newtest -> newtest

获取版本库更新

(当其他人更新了文件,这时你需要刷新克隆版本库)

[root@localhost public_html]# git pull

pull意味着先执行fetch,然后执行merge或rebase。

push和fetch都负责在版本库之间传输数据,但方向相反。

(3)图解远程版本库开发周期

最初的开发

克隆产生两个单独的版本库

交替的历史记录



获取交替记录

合并历史记录

推送合并后的历史记录

最新文章

  1. Oracle学习笔记十三 触发器
  2. Android 中常见控件的介绍和使用
  3. Windows Phone 8.1中处理后退键的HardwareButtons.BackPressed事件
  4. 立即调用的函数表达式IIFE
  5. Spring Data JPA教程, 第三部分: Custom Queries with Query Methods(翻译)
  6. python27读书笔记0.2
  7. HDU 4720 Naive and Silly Muggles 2013年四川省赛题
  8. 方案猿身高project联赛,艺术家,相反,养殖场!-------三笔
  9. Java基础之数据类型、内存、修饰符、代码块
  10. 如何安装MySQL5.5.62
  11. 使用docker部署ambari的若干要点
  12. 2018-10-19,下午4点拿到京东offer
  13. kafka学习1:kafka安装
  14. Windows查看指定端口是否占用和查看进程
  15. 对象序列化:pickle和shelve
  16. spring cloud 学习(8) - sleuth & zipkin 调用链跟踪
  17. node学习笔记6——自定义模块
  18. Python day5_tuple元祖的常见方法1_笔记
  19. linux查看网卡驱动
  20. 搭建互联网架构学习--005--框架初步拆分ssm单一框架

热门文章

  1. hdu1024(最大m串子序列)
  2. 【BZOJ4155】[Ipsc2015]Humble Captains 最小割+DP
  3. ios 将p12文件转换为pem
  4. node 事件监听器
  5. Delphi开发的服务在Windows2003 64位注册方式。
  6. Spoken English Practice(Don't get me wrong, that explanation makes no difference, I'm still mad at you. Come on, be reasonable!)
  7. Big Data资料汇总
  8. C++之贪吃蛇
  9. HttpRunner 参数化数据驱动
  10. mysql删除重复数据,保留最新的那一条