Github Branch,Tag:如何获得特定的代码版本?

时间:2022-10-27 10:27:51

I'm new to Git hub and I got confused about the concept of tag and branch(explained here) I would like to get an stable version of PhantomJS(version 2.1.0) from git hub. But I don't understand if I should do:

我是Git hub的新手,我对标签和分支的概念感到困惑(这里解释)我想从git hub获得一个稳定版的PhantomJS(版本2.1.0)。但我不明白我是否应该这样做:

git checkout master
git remote add upstream https://github.com/ariya/phantomjs.git
git fetch upstream
git rebase --onto tags/2.1.0 upstream/master master

or

要么

git init
git remote add -t 2.1 -f origin https://github.com/ariya/phantomjs.git
git checkout 2.1

Would you please explain me which one and why?

你能解释一下,为什么?

2 个解决方案

#1


5  

You should just clone the repository and then checkout the tag:

您应该只是克隆存储库,然后签出标记:

$ git clone https://github.com/ariya/phantomjs.git
$ cd phantomjs
$ git checkout 2.1

Keep in mind that being on a tag, you cannot commit any local change you would make. For that, you must be on a branch. What can be confusing is that the command is git checkout for both branches and tags.

请记住,在标记上,您不能提交任何本地更改。为此,你必须在一个分支上。令人困惑的是该命令是分支和标签的git checkout。

#2


1  

I am not sure if I understood your question correctly but I will try to answer on it:

我不确定我是否理解你的问题,但我会尽力回答:

Git stores data about all changes that made in code (this include data about branches and tags) When you clone a repository you will get complete history for that repository

Git存储有关代码中所做的所有更改的数据(这包括有关分支和标记的数据)克隆存储库时,您将获得该存储库的完整历史记录

So, git clone https://github.com/ariya/phantomjs.git will clone project
If you have forked project you can do
git clone https://github.com/<YOUR_USERNAME>/phantomjs.git

那么,git clone https://github.com/ariya/phantomjs.git将克隆项目如果你有分叉项目你可以做git clone https://github.com/ /phantomjs.git

Now change directory to phantomjs: cd phantomjs/

现在将目录更改为phantomjs:cd phantomjs /

To see history you can execute git log or git log --oneline --decorate --graph for prettier view

要查看历史记录,您可以执行git log或git log --oneline --decorate --graph以获得更漂亮的视图

To list all tags on repository execute
git tag

列出存储库执行git标记的所有标记

Finally, to create branch with tab 2.1.0 execute
git checkout 2.1.0 -b v2.1.0
After this you will have two branches master and v2.1.0

最后,用tab 2.1.0创建分支执行git checkout 2.1.0 -b v2.1.0之后你将有两个分支master和v2.1.0

I hope this helps

我希望这有帮助

#1


5  

You should just clone the repository and then checkout the tag:

您应该只是克隆存储库,然后签出标记:

$ git clone https://github.com/ariya/phantomjs.git
$ cd phantomjs
$ git checkout 2.1

Keep in mind that being on a tag, you cannot commit any local change you would make. For that, you must be on a branch. What can be confusing is that the command is git checkout for both branches and tags.

请记住,在标记上,您不能提交任何本地更改。为此,你必须在一个分支上。令人困惑的是该命令是分支和标签的git checkout。

#2


1  

I am not sure if I understood your question correctly but I will try to answer on it:

我不确定我是否理解你的问题,但我会尽力回答:

Git stores data about all changes that made in code (this include data about branches and tags) When you clone a repository you will get complete history for that repository

Git存储有关代码中所做的所有更改的数据(这包括有关分支和标记的数据)克隆存储库时,您将获得该存储库的完整历史记录

So, git clone https://github.com/ariya/phantomjs.git will clone project
If you have forked project you can do
git clone https://github.com/<YOUR_USERNAME>/phantomjs.git

那么,git clone https://github.com/ariya/phantomjs.git将克隆项目如果你有分叉项目你可以做git clone https://github.com/ /phantomjs.git

Now change directory to phantomjs: cd phantomjs/

现在将目录更改为phantomjs:cd phantomjs /

To see history you can execute git log or git log --oneline --decorate --graph for prettier view

要查看历史记录,您可以执行git log或git log --oneline --decorate --graph以获得更漂亮的视图

To list all tags on repository execute
git tag

列出存储库执行git标记的所有标记

Finally, to create branch with tab 2.1.0 execute
git checkout 2.1.0 -b v2.1.0
After this you will have two branches master and v2.1.0

最后,用tab 2.1.0创建分支执行git checkout 2.1.0 -b v2.1.0之后你将有两个分支master和v2.1.0

I hope this helps

我希望这有帮助