2021年2月5日 星期五

[Git 常見問題] Download/Checkout a specific tag with Git

 Source From Here

Question
I'm trying to figure out how I can download a particular tag of a Git repository and how can I check out to a specific tag?

HowTo
Execute below command will give you the whole repository:
$ git clone

After the clone, you can list the tags with git tag -l and then checkout a specific tag:
$ git checkout tags/<tag_name>

Even better, checkout and create a branch (otherwise you will be on a branch named after the revision number of tag):
$ git checkout tags/<tag_name> -b <branch_name>

One simple example as below:
// Check commits
$ git log --oneline
4ceccb1 (HEAD -> latest) update Test
ad16543 (tag: v0.0.2) commit for v0.0.2
bb134c5 ([b]tag: v0.0.1, my_branch) Update 105M.img[/b]
faa8827 Upload large file >50M
66f0f1a Another commmit for merge testing
...


$ git tag -l
v0.0.1
v0.0.2


// Checkout to commit with tag v0.0.1
$ git checkout tags/v0.0.1
Note: switching to 'tags/v0.0.1'.

You are in 'detached HEAD' state. You can look around, make experimental
...


$ git log --oneline | head -2
bb134c5 Update 105M.img
faa8827 Upload large file >50M


// Return back to original commit
$ git checkout master
$ git log --oneline | head -n 1
4ceccb1 (HEAD -> latest) update Test

$ git checkout tags/v0.0.2 -b tag_0.0.2
Switched to a new branch 'tag_0.0.2'

$ git log --oneline
ad16543 (HEAD -> tag_0.0.2, tag: v0.0.2) commit for v0.0.2
bb134c5 (tag: v0.0.1, my_branch) Update 105M.img
faa8827 Upload large file >50M
...


沒有留言:

張貼留言

[Git 常見問題] error: The following untracked working tree files would be overwritten by merge

  Source From  Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 #   git clean -d -fx 方案2: 今天在服务器上  gi...