远程版本库

(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)图解远程版本库开发周期

最初的开发

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

交替的历史记录



获取交替记录

合并历史记录

推送合并后的历史记录

GIT使用—创建并使用远程版本库的更多相关文章

  1. Git远程版本库

    目前为止,所有的Git操作都是在一个本地版本库中.现在是时候来体验Git分布式的特性了. 说到远程版本库,大家最为熟悉的就是GitHub了,它实际上就相当于一个远程版本库,托管着所有的本地版本库的提交 ...

  2. git 创建远程版本库(亲测有效)

    一.github远程版本库 1.创建SSH Key(windows)   ssh-keygen -t rsa -C "youremail@example.com"   2.连接版本 ...

  3. 关于Git远程版本库

    Git作为分布式版本库控制系统,每个人都是本地版本库的主人,可以在本地的版本库中随心所欲的创建分支和里程碑. 当需要多人协作时,问题就出现了: 1.如何避免因为用户把所有的本地分支都推送到了共享版本库 ...

  4. Git学习笔记---安装与初始化 连接远程版本库

    1.Git的安装 sudo apt-get install git 用的是linux(ubuntu)系统,安装非常简单,上面一条命令就够了. 2.初次运行的配置 Git 提供了一个叫做 git con ...

  5. Git的使用(3) —— 远程版本库的操作(GitHub)

    1. 配置SSH (1) GitHub 登陆GitHub后,点击右上角头像,选择 Setting . 在左面栏目中选择"SSH and GPG keys". 打开生成的SSH公钥文 ...

  6. GitHub学习三-远程版本库更新与提交

    1.远程版本库更新 一般来说,将本地与远程相关联之后,首先将数据从远程更新下来再上传比较好. 输入 git pull origin master 如果新建版本库的话勾选了初始化包含readme.md, ...

  7. git 远程版本库,github提供服务原理,git自动更新发送邮件

    1.安装好Linux,安装好Git(192.168.1.239) 2.创建一个用户zph(让此用户提供git on server),密码设置为12345678 # useradd zph # pass ...

  8. 关于git远程版本库的一些问题之解决

    Part1:CentOS6.5免密码登录 修改/etc/ssh/sshd_config RSAAuthentication yesPubkeyAuthentication yesAuthorizedK ...

  9. git 远程版本库

    [root@localhost workspace]# cd repos/ [root@localhost repos]# ll 总用量 drwxr-xr-x root root 12月 : hell ...

随机推荐

  1. Win7下搭建安卓android开发环境

    本文出自 “孤狼” 博客,请务必保留此出处http://332374363.blog.51cto.com/5262696/1310882 另外,在搭建android开发环境时,还参考了http://w ...

  2. [SharePoint 2010]Sandboxed Solution (沙箱解決方案)

    現有的SharePoint 2007系統中,我們如果要安裝客製化的程式碼到系統中,我們必須製作一個解決方案包裝檔(Solution Package),然後在系統的中央管理後台中,真對整個伺服器農場Fa ...

  3. Max_connect_errors – MySQL性能参数详解

    转载http://blog.csdn.net/wulantian/article/details/9670957 ax_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过 ...

  4. 基于xml文件的格式配置Spring的AOP

    用例子直接说明: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  5. c#修改cpu主频

    并不是真正能修改硬件,只是一个数据,能骗过部分程序检测,如英雄联盟必须达到3.0的主频才能使用录像功能,通过修改可以达到要求. 下面是代码: public enum RegValueKind { // ...

  6. SqlServer SqlBulkCopy批量插入 -- 多张表同时插入(事务)

    这段时间在解决一个多个表需要同时插入大量数据的问题,于是在网上找了下,查到说用SqlBulkCopy效率很高,实验后确实很快,10万条数据只要4秒钟,用ef要用40秒.但是我的还需两张表同时插入,且需 ...

  7. .def文件如何编写

    DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明. 规则是:1.首先创建 一个DL ...

  8. Excel文本型数据转为数值型的方法

    操作步骤非常简单,适用于所有版本的Excel. 在任意一个空白单元格中输入数值1,然后选中该单元格,执行复制操作: 选中需要转换的单元格(或区域),执行“编辑.选择性粘贴”命令,打开“选择性粘贴”对话 ...

  9. 执行Java脚本firefox启动成功,不运行test方法,且提示NullPointerException

    在ideal中新建maven项目,将录制好的Java脚本文件,直接复制到项目中,添加相关的依赖脚本. 代码不报错之后,运行录制好的Java脚本,启动了firefox之后,不执行test方法,报错Nul ...

  10. 20165324 《Java程序设计》第3周学习总结

    20165324 <Java程序设计>第3周学习总结 教材学习内容总结 本周学习内容如下: 编程语言思想 面向过程语言的核心是编写解决某个问题的代码块:在面向对象语言中,最核心的内容是对象 ...