git入门三(远程、标签)

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 基本操作,创建和克隆仓库,更新,暂存和克隆仓库,暂存并提交更新等,以及查看历史更新记录等。
 
 
 
 
 
 
 
 
 
 
 
 
 
posted @ 2014-03-10 22:44  AndyYu  阅读(2363)  评论(0编辑  收藏  举报