因某種需要去了解git tag的使用,
常用的情況為
project A finished --> tag V1.0 --> deploy product env --> add function / debug --> tag V1.1 --> deploy product env --> ...
主要的用途為product的版本控管.(增修功能或是debug)
那麼有幾個基本操作需要知道
將修改commit到local repository
git commit -a -m '註解' ##如果有新增檔案還是需要先加入(使用git add file .)
顯示目前的tags
git tag -l
新增tag到local repository
git tag -a tag_name -m '註解'
將commit後的結果push到remote repository
git push origin master ## origin master是分支的指定,如果你的repository只有origin/master,則可省略為git push
將tag push到remote repository,tag要額外自行push
git push --tags ## 或指定特定的tag_name
將remote repository拉下來
git clone user@host:path/repository_name.git
並還原成特定的tag版本
git checkout tag_name ##此時不可對此專案作修改,tag就像DB快照一樣
刪除local repository的tag
git tag -d tag_name
刪除remote repository的tag
git push origin :refs/tags/tag_name
建立特定tag的branch
git checkout -b branch_name tag_name
或
git branch branch_name tag_name
與不同commits比較差異
git diff tag_name commit_id ## 可以使用git log來看commit編號,或使用HEAD來代表當前的最新版本
參考