GitHub-clone切换源码分支版本:

众所周知,在GitHub上的源码会一直进行版本的迭代更新,clone的虽然是同一个网址,但是版本可能会因近期更新过,也就是master主分支发生了变更(被打了补丁进行更新),变成了新版本。旧版本被打上了版本号的tag。当然也可以进入git项目中去找到旧版本的分支,复制网址链接进行clone;还有一种方法就是本文要说的。

同样使用项目地址进行clone项目的master主分支。

git clone https://github.com/xxx/xxx.git     # 网址为项目链接

进入项目目录可查看项目分支

cd xxx.git    # 进入项目目录
git branch -av  # 查看当前使用分支,-a,显示本地和远程分支
# 带*的是当前使用的分支,且是本地分支,其他remotes是远程分支
* master                           85015db [origin/master] Merge pull request #65 from open-ness/openness_release_2009
  remotes/origin/HEAD              -> origin/master
  remotes/origin/master            85015db Merge pull request #65 from open-ness/openness_release_2009
  remotes/origin/oek-pull-2003-tag f38769e Retain OEK 20.03 to pull 20.03 tags

切换tag

查看在主分支中的版本tag有哪些

[root@localhost openness-experience-kits]# git tag
openness-19.12.01
openness-19.12.01_1
openness-19.12.01_2
openness-20.03
openness-20.03.01
openness-20.06
openness-20.06-ovn-fix
openness-20.06.01
openness-20.09

切换指定分支版本

[root@localhost openness-experience-kits]# git checkout openness-20.06.01
Note: checking out 'openness-20.06.01'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 5ebe82d... Merge pull request #58 from open-ness/openness_rel_200601

查看当前的branch,这里只查看了本地的branch

可以看到当前使用的没有name

[root@localhost openness-experience-kits]# git branch
* (detached from openness-20.06.01)
  master

设置当前使用branch_name

[root@localhost openness-experience-kits]# git checkout -b openness-20.06.01
Switched to a new branch 'openness-20.06.01'
[root@localhost openness-experience-kits]# git branch
  master
* openness-20.06.01

切换commit

实际和tag的切换方法是一样的,如果客户或者产品有对应的项目commit值的情况下:

# 默认使用commit值的前七位即可,全部值也可以的
git checkout xxxxxxx
# 定义一个本地分支名
git checkout -b xxx

如果不知道具体哪个commit值,可通过git log查看

 

https://www.feiyiblog.com/2020/10/19/GitHub-clone%E5%88%87%E6%8D%A2%E6%BA%90%E7%A0%81%E5%88%86%E6%94%AF%E7%89%88%E6%9C%AC/

posted @ 2022-02-21 10:14  小啊菜鸡  阅读(819)  评论(0编辑  收藏  举报