Git tag: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(8 intermediate revisions by the same user not shown)
Line 12: Line 12:
Create, list, delete or verify a [[Git_Concepts#Tag|tag object]]. To check out the [[Git Concepts#Commit|commit]] associated with a specific [[Git Concepts#Tag|tag]] into a [[Git Concepts#Detached_HEAD|detached HEAD]], see [[Git_checkout#Checkout_a_Tag_into_a_Detached_HEAD|git checkout]].
Create, list, delete or verify a [[Git_Concepts#Tag|tag object]]. To check out the [[Git Concepts#Commit|commit]] associated with a specific [[Git Concepts#Tag|tag]] into a [[Git Concepts#Detached_HEAD|detached HEAD]], see [[Git_checkout#Checkout_a_Tag_into_a_Detached_HEAD|git checkout]].


By default, tags are not pushed to remote server. For more details see [[]] below.
By default, tags are not pushed to remote server.
 
=Ensuring All Tags Are Accessible from the Local Workarea=
 
To make sure all the tags are accessible from the local workarea, run:
 
<syntaxhighlight lang='bash'>
git fetch --all --tags
</syntaxhighlight>
 
If tags are not explicitly fetched, you may run in the following situation even after running <code>git fetch</code> without other arguments.
 
<syntaxhighlight lang='bash'>
git checkout my-tag
error: pathspec 'my-tag' did not match any file(s) known to git
</syntaxhighlight>


=List Tags=
=List Tags=
Line 23: Line 38:


  git tag -l
  git tag -l
=Display the Commit a Tag Points To=
<syntaxhighlight lang='bash'>
git rev-list -n 1 <tag-value>
</syntaxhighlight>
Also see: {{Internal|Git_rev-list#Overview|<tt>git rev-list</tt>}}


=Create a Tag=
=Create a Tag=
Line 56: Line 77:
If tag was pushed to a remote repository and now it should be removed, deleting it locally and then <tt>push --follow-tags</tt> is NOT sufficient.
If tag was pushed to a remote repository and now it should be removed, deleting it locally and then <tt>push --follow-tags</tt> is NOT sufficient.


You need to remove it locally following [git tag#RemoveTag] and then
You need to [[#Remove_a_Tag_Locally|remove it locally]], then:
 
{{{
git push origin :refs/tags/<my-tag-name>
}}}
 
Result:
 
{{{
NOMBP2:api ovidiu$ git push origin :refs/tags/release-test-1


To git@github.com:amgenpaas/api.git
git push origin :refs/tags/<''tag-name-to-remove''>
- [deleted]        release-test-1
}}}

Latest revision as of 00:01, 11 August 2023

External

Internal

Overview

Create, list, delete or verify a tag object. To check out the commit associated with a specific tag into a detached HEAD, see git checkout.

By default, tags are not pushed to remote server.

Ensuring All Tags Are Accessible from the Local Workarea

To make sure all the tags are accessible from the local workarea, run:

git fetch --all --tags

If tags are not explicitly fetched, you may run in the following situation even after running git fetch without other arguments.

git checkout my-tag
error: pathspec 'my-tag' did not match any file(s) known to git

List Tags

Tags can be listed based on a given pattern. All tags are listed if no pattern is given.

git tag [-l] [name-pattern]
git tag
git tag -l

Display the Commit a Tag Points To

git rev-list -n 1 <tag-value>

Also see:

git rev-list

Create a Tag

git tag '<tag-name>'

Pushing a Tag to a Remote Server

By default, the git push command doesn’t transfer tags to remote servers. You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches  - you can run git push origin <tagname>:

git push origin <tagname>
git push origin release-1.2.1

Pushing All Tags

git push origin --tags

Alternatively:

git push --follow-tags

or set "push.followTags" to do this automatically on each push.

Remove a Tag

Remove a Tag Locally

git tag -d <tag-name>

Remove a Tag Remotely

If tag was pushed to a remote repository and now it should be removed, deleting it locally and then push --follow-tags is NOT sufficient.

You need to remove it locally, then:

git push origin :refs/tags/<tag-name-to-remove>