Git:通过标签从远程拉取
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12627856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: Pulling from Remote by Tag
提问by ImpGuard
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.
我是 git 的初学者,一直在我的本地计算机上测试几个命令,方法是创建一个本地存储库来进行拉取和推送。
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.
我在“项目”中设置了一个裸存储库,并从中克隆了两个用户:“user1”和“user2”。该项目目前有文件“one.txt”、“two.txt”等和一些标记为“v1.0”、“v2.0”等的提交,这些提交与添加新的“#.txt”文件相关。
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:
但是,当我尝试在新文件夹“tmp”中创建新的 git 工作目录,将项目添加为远程存储库(tmp 不是克隆)并拉取时,出现错误:
$ 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?
当我只是尝试从项目中拉取 master 分支时不会发生这种情况,所以我假设我有拉取权限。这是怎么回事?
回答by Adam Dymitruk
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).
您要做的就是创建另一个克隆。除非您有充分的理由不这样做,否则它会复制所有历史记录(不用担心,由于压缩,它通常小于 svn 存储库大小的 10%,并且通常小于工作目录)。
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
两个操作fetch
,并merge
在同一时间完成pull
。所以你可以这样做
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.
所以标签被获取。当您意识到 pull 是 fetch 和 merge(或者如果您愿意的话,可以 rebase)放在一起时,这就暗示了这一点。
回答by vinnydiehl
You already have the tags in your history. You can use git tag -l
to list all available tags, and you can git checkout
to them at any time.
您的历史记录中已经有了这些标签。您可以使用git tag -l
来列出所有可用的标签,并且您可以git checkout
随时使用它们。
git checkout v1.0