git 入门三 (远程、标签)
 
  分布式版本控制管理系统本地仓库和中心服务器仓库数据是本地的镜像仓库,中心服务器数据仓库的是为了多用户数据合并和获取同步的中心,多人协作需要管理这些远程仓库,以便推送和拉去数据,汇总各自项目的进度和工作成果。管理远程仓库的工作添加远程库,废弃远程库,管理远程分支管理等等。每次用户从中心服务器拉去文件不仅仅是最新版本的文件数据,同事还包含了所有历史数据,现在我们来看看远程服务器数据仓库的使用。我们已github 测试项目作为远程服务器数据仓库作为操作环境。

 
1、克隆一个仓库
 
$ git clone git@github.com:andy/test.git
Cloning into 'test'...
remote: Reusing existing pack: 4, done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.
$ git remote
origin
 
$ git remote -v
gshell  https://gitshell.com/andy/test.git (fetch)
gshell  https://gitshell.com/andy/test.git (push)
origin  git@github.com:andy/test.git (fetch)
origin  git@github.com:andy/test.git (push)
 
 
$ cat .git/config
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:andy/test.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "gshell"]
        url = https://gitshell.com/andy/test.git
        fetch = +refs/heads/*:refs/remotes/gshell/*
 
2、添加远程仓库
 
git remote 可以查询远程仓库简短名称,在克隆某个项目后,至少可以看到可以名为origin的远程库,git用这个默认标识你克隆的原始仓库。我们现在也可以添加一个新的仓库。从远程仓库获取数据git fetch remote-name,会从远程数据仓库拉去你本地没有的数据,拉去完成后,可以和你本地的一个分支做合并,开始我么克隆一个仓库,系统会默认把仓库归于origin名下,git fetch origin 会抓取你从上次更新以来有别人更新到服务器的新内容,fetch只是从远端的数据拉取到本地仓库,并不合并到当前工作分支。只有使用 git pull origin 命令会自动抓取数据下来,然后将远端分支自动合并到本地仓库中的当前分支,日常工作中都这样使用,又快有好。
 
$ git remote add gitcsdn  git@code.csdn.net:andy_yyf/test.git
 
$ git remote -v
gitcsdn git@code.csdn.net:andy_yyf/test.git (fetch)
gitcsdn git@code.csdn.net:andy_yyf/test.git (push)
gshell  git@gitshell.com:andy/test.git (fetch)
gshell  git@gitshell.com:andy/test.git (push)
origin  git@github.com:andy/test.git (fetch)
origin  git@github.com:andy/test.git (push)
 
 
$ git fetch gshell
From gitshell.com:andy/test
 * [new branch]      master     -> gshell/master
 
 
3、推送数据到远程仓库
 
 在工作中项目开发完成部分,需要推送到远程服务器和大家合并共享工作内容。需要将本地仓库数据推送到远程仓库,实现这个命令和简单,
git pull remote-name branch-name ,如果被本地分支master 分支推送到origin 服务器上。只要在中心服务器有权限,或者同一时候没有其他人也在推送数据,或者从最近推送或获取后有其他人以后更新,可以直接推送到远程仓库,如果别人已有更新,需求把远程更新的数据抓取到本地合并后再推送。
 
 
$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 330 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:andy/test.git
   7b26911..894ed8b  master -> master
 
$ git push gshell
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 330 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitshell.com:andy/test.git
   7b26911..894ed8b  master -> master
 
$ git push gitcsdn
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 330 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@code.csdn.net:andy_yyf/test.git
   7b26911..894ed8b  master -> master
 
 
4、查看远程仓库信息

  
查看远程仓库信息 git remote show remote-name ,查看某个远程仓库的详细信息,
 
    $ git remote show origin
* remote origin
  Fetch URL: git@github.com:andy/test.git
  Push  URL: git@github.com:andy/test.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (up to date)
 
5、远程仓库本地配置别别名修改
 
远程仓库本地.git/config 配置文件中本地短名称修改 git remote rename oldname newname.远程仓库有变化,如远程的镜像不再使用,或者原来的克隆不再使用,需要异常远端仓库,可以git remote rm 命令。  通过本地修改本地配置文件,需求修改文件内容存放在.git/config 的文件中。
 
$ git remote rename gitcsdn gcsdn
 
$ cat .git/config
 
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:andy/test.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "gshell"]
        url = git@gitshell.com:andy/test.git
        fetch = +refs/heads/*:refs/remotes/gshell/*
[remote "gcsdn"]
        url = git@code.csdn.net:andy_yyf/test.git
        fetch = +refs/heads/*:refs/remotes/gcsdn/*
 
$ git remote rm gshell
 
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@github.com:andy/test.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "gcsdn"]
        url = git@code.csdn.net:andy_yyf/test.git
        fetch = +refs/heads/*:refs/remotes/gcsdn/*
  
6、标签
 
版本打标签是在某一个版本发布或者对应的提交上打标签,git tag  tagName 命令是打标签的命令,带有备注信息的标签需要 git  tag -a v1.0 -m "xxxx" 的标签,标签使用有两种类型,前一种是轻量级(lightweight) 和含付注释的(annotated),轻量级标签就像是个不会变化的分支,实际上它就是个指向特定提交对象的引用。而含付注释的标签,实际上是在存储仓库中的一个独立对象,对象存放在.git/objects/中,它有自身的校验和信息,包含着标签的名字,电子邮件地址和日期,以及标签说明,标签本身也允许GNU privacy Guard(GPG)来签署或验证。一般我们都使用含有付注释型的标签,以便保留相关信息,当然如果只是临时性的添加标签,或者不需要添加额外信息,就可以用轻量级的标签。用git show 可以查看提交对象信息上,列出了标签的提交者和提交时间,以及标签的说明。
 
$ git tag -a v1.0 -m"it the tag v1.0"
 
$ git tag
v1.0
 
$ git show v1.0
commit 894ed8b9883fac03c386d2d26317375797853586
Author: andy <andy@gmail.com>
Date:   Mon Mar 10 16:46:50 2014 +0800
 
    local 2st commit“
 
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..c261c57
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1 @@
+git introduction
 
版本提已提交到仓库,或者某个历史提交记录上打标签,也可以打标签,只需要在标签后加上对应的校验和,如下后补上上标签:
 
$ git tag v1.1.1 2e9cc
 
$ git show v1.1.1
commit 2e9cc04f50e000d5280979348e7084afcb9d35f2
Author: andy <andy@gmail.com>
Date:   Mon Mar 10 22:19:03 2014 +0800
 
     3rd commit
 
diff --git a/readme.txt b/readme.txt
index c261c57..2b92ac4 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1,2 @@
 git introduction
+the current release version 1.8.0
 
 
标签只会保存在本地,暂存区对象也是只保存在本地,在推送仓库的时候不会推送到远程服务器上,标签可以推送到远程服务器,需要通过显式命令才能将标签签到远程仓库,其命令方式犹如推送分支,运行git push origin tagname,推送本地所有标签 --tags,其它人在拉取数据的时候也会看到对推送到服务器的标签。
 
$ git push origin v1.1.1
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 287 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To git@github.com:andy/test.git
 * [new tag]         v1.1.1 -> v1.1.1
 
$ git push origin --tags
Counting objects: 1, done.
Writing objects: 100% (1/1), 148 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@github.com:andy/test.git
 * [new tag]         v1.0 -> v1.0
 * [new tag]         v1.1 -> v1.1
 
 
 
git 基本操作,创建和克隆仓库,更新,暂存和克隆仓库,暂存并提交更新等,以及查看历史更新记录等。
 
 
 
 
 
 
 
 
 
 
 
 
 

git入门三(远程、标签)的更多相关文章

  1. git入门 创建版本库, 版本管理 分支 标签

    参考: https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 GIT最流行的分布式版本 ...

  2. git 入门教程之里程碑式标签

    "春风得意马蹄疾,一日看尽长安花",对于项目也是如此,最值得期待的恐怕就要数新版本发布的时刻了吧?每当发布新版本时要么是版本号命名(比如v0.0.1)或者代号命名(比如Chelse ...

  3. Git入门——远程仓库及分支管理

    关于本地版本库的操作,请见:Git入门--本地版本库操作 本篇提到的所有命令: 小结 前面提到,Git相对于传统的SVN有着很大的优势,其中之一就在于集中式系统中,版本库只能存在于中央服务器上:而在G ...

  4. git 学习使用总结三(远程仓库操作)

    这篇文章仅供自己以后翻阅加深记忆,要系统的学习 git 教程(中文版),请移步到 liaoxuefeng.com 学习 git 教程部分. pull, fetch, clone, push, chec ...

  5. [置顶] 【Git入门之十一】标签管理

    原创作品,转载请标明:http://blog.csdn.net/jackystudio/article/details/12309731 标签是啥?标签就是给某个版本的一个标记. 1.为当前版本创建标 ...

  6. GIT入门笔记(18)- 标签创建和管理

    git tag <name>用于新建一个标签,默认为HEAD,也可以指定一个commit id: git tag -a <tagname> -m "blablabla ...

  7. git 入门教程之本地和远程仓库的本质

    本地仓库和远程仓库在本质上没有太大区别,只不过一个是本地电脑,一个是远程电脑. 远程仓库不一定非得是 github 那种专门的"中央服务器",甚至局域网的另外一台电脑也可以充当&q ...

  8. Git(三)Git的远程仓库

    一. 添加远程库 现在我们已经在本地创建了一个Git仓库,又想让其他人来协作开发,此时就可以把本地仓库同步到远程仓库,同时还增加了本地仓库的一个备份.常用的远程仓库就是github:https://g ...

  9. Git 推送和删除远程标签

    事实上Git 的推送和删除远程标签命令是相同的,删除操作实际上就是推送空的源标签refs: git push origin 标签名 相当于 git push origin refs/tags/源标签名 ...

随机推荐

  1. JDBC-登陆功能实现

    1.user.java package songyan.jdbc.entity; import java.util.Date; public class User { private int id; ...

  2. 每天一个linux命令8之grep高级篇

    1语法       grep -[acinv] '搜索内容串' filename -a 以文本文件方式搜索-c 计算找到的符合行的次数-i 忽略大小写-n 顺便输出行号-v 反向选择,即找 没有搜索字 ...

  3. git回退到某个commit

    git log查看提交历史及提交的commit_id 回退命令: $ git reset --hard HEAD^ 回退到上个版本$ git reset --hard HEAD~3 回退到前3次提交之 ...

  4. 阿里蚂蚁的前端ant-design

    蚂蚁国内镜像: http://ant-design.gitee.io/components/date-picker-cn/ 阿里的设计平台:https://design.alipay.com/deve ...

  5. rabbitmq集群节点操作

    节点恢复过程中把数据删掉很重要,恢复一单结点,再清数据 节点增加: 1. rabbitmq-server -detached   --- .erlang.cooike的权限,400 属主rabbitm ...

  6. [iOS 高级] iOS远程推送与本地推送大致流程

    本地推送: UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { ...

  7. mac 上python编译报错No module named MySQLdb

    mac 上python编译报错No module named MySQLdb You installed python You did brew install mysql You did expor ...

  8. How to get the edited text from itext in fabricjs

    https://stackoverflow.com/questions/39286826/how-to-get-the-edited-text-from-itext-in-fabricjs http: ...

  9. select、poll、epoll之间的区别总结[整理](转)

    select,poll,epoll都是IO多路复用的机制.I/O多路复用就通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作.但select ...

  10. maven生成jar包

    改了部分cas源码,想重新生成jar包,只好试着脱离eclipse,学了一下maven打jar包的命令,记录如下: 1.首先下载maven (请注意自己的jdk版本,如果使用maven2建议使用jdk ...