Git:通过标签从远程拉出 [英] Git: Pulling from Remote by Tag

查看:107
本文介绍了Git:通过标签从远程拉出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的初学者,并且通过创建本地存储库来测试本地计算机上的一些命令,以便从中拉取和推送。



我在'项目'中设置了一个裸仓库,并从中克隆了两个用户:'user1'和'user2'。该项目目前具有文件'one.txt','two.txt'等,以及与添加新的#.txt文件相关联的一些标记为v1.0,v2.0等的提交。但是,当我尝试在新文件夹'tmp'中创建新的git工作目录时,将该项目添加为远程存储库(tmp不是克隆),和拉,我得到的错误:

  $ git pull ../project v1.0 
$致命:'' v1.0'似乎不是一个混帐存储库
$ fatal:远程端意外挂起

当我只是试图从项目中拉出主分支时,这种情况不会发生,所以我认为我有权拉取。发生什么事?

解决方案

您要做的就是创建另一个克隆。除非你有充分的理由不这样做,否则它将复制所有的历史记录(不用担心,它通常小于svn回购的大小的10%,并且由于压缩而通常小于工作目录)。



创建您的第一个回购:

  mkdir myrepo 
cd!$
git init
echo one> one.txt
git add -A
git commitmy first commit
git tag v1.0
echo two> two.txt
git add -A
git commitmy second commit
git tag v2.0

创建一个模拟的中央仓库:

$ $ $ $ $ $ $
cd!$
git init --bare#不想在这里有一个工作目录
cd -

创建一个模拟同事回购:

  mkdir coworkerrepo 
cd!$
git init

告诉您的仓库中央仓库是哪里

  cd ../myrepo 
git remote add origin ../centralrepo

告诉你的同事回购中央回购的地方是什么?

  cd ../ coworkerrepo 
git remote add origin ../centralrepo

将您的工作发布到中央仓库:

  cd  - #两个dir之间翻转的有用快捷方式(适用于git checkout和分支)
git push origin主

放置主引用和提交内,但不提供标记。对于标签,执行此操作:

  git push origin v1.0 
git push origin v2.0

或者只需将您的回购中的所有代码与

  git push origin --tags 

您现在可以检查远程有这些标签和引用

  git remote -v show origin 

切换到您的同事资源库并获取这些更改:

  cd  -  
git fetch#将更新跟踪分支和标签
git合并origin / master#快速转发主分支到远程跟踪分支指向的内容

两个操作 fetch 合并 pull 的同时完成。所以你可以这样做,而不是

  git pull origin master 

所以标签被抓取。这意味着当你意识到拉是取和合并(如果你想要重组)。


I'm a beginner at git and have been testing a couple of commands on my local computer by creating a local repository to pull and push from and to.

I setup a bare repository in 'project' and cloned two users: 'user1' and 'user2' from it. The project currently has the files 'one.txt', 'two.txt' etc. and a few commits tagged with 'v1.0', 'v2.0' etc. associated with adding a new "#.txt" file.

However, when I attempt to create a new git working directory in a new folder 'tmp', adding the project as a remote repository (tmp is not a clone), and pulling, I get the error:

$ git pull ../project v1.0
$ fatal: 'v1.0' does not appear to be a git repository
$ fatal: The remote end hung up unexpectedly

This doesn't happen when I simply try to pull the master branch from project, so I assume I have permissions to pull. What's going on?

解决方案

All you want to do is create another clone. Unless you have good reason not to do it, it will duplicate all history (don't worry, it's usually <10% the size of an svn repo and often smaller than the working dir due to compression).

Create your first repo:

mkdir myrepo
cd !$
git init
echo one > one.txt
git add -A
git commit "my first commit"
git tag v1.0
echo two > two.txt
git add -A
git commit "my second commit"
git tag v2.0

Create a simulated central repo:

cd ..
mkdir centralrepo
cd !$
git init --bare # don't want to have a working directory here
cd -

Create a simulated coworker repo:

mkdir coworkerrepo
cd !$
git init

Tell your repo where the central repo is

cd ../myrepo
git remote add origin ../centralrepo

Tell your coworker's repo where the central repo is

cd ../coworkerrepo
git remote add origin ../centralrepo

Publish your work to the central repo:

cd - # useful shortcut for flipping between two dirs (works for git checkout and branches too)
git push origin master 

puts up the master reference and the commits within, but not tags. For tags, do this:

git push origin v1.0
git push origin v2.0

or just push up all tags in your repo with

git push origin --tags

you can now check that the remote has those tags and references with

git remote -v show origin

switch to your coworker's repository and get those changes:

cd -
git fetch # will update tracking branches and tags
git merge origin/master # fast-forward master branch to what the remote tracking branch is pointing to

the two operations fetch and merge are done at the same time with pull. So you could have done this instead

git pull origin master

So tags get fetched. This is implied when you realize that pull is fetch and merge (or rebase if you want) put together.

这篇关于Git:通过标签从远程拉出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆