Git: Pulling from Remote by Tag

喜夏-厌秋 提交于 2019-12-23 15:38:45

问题


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?


回答1:


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.




回答2:


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 checkout v1.0


来源:https://stackoverflow.com/questions/12627856/git-pulling-from-remote-by-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!