वरुण
वरुण

Reputation: 1685

Delete tags from feature branch

We are using Bitbucket for maintaining our code. We have policy to not to push tags.

I have created a feature branch named myFeature and fetched on local.

Made some changes in files committed and pushed.

Later found that there were tags on local:

enter image description here

Deleted the tags from local: enter image description here

How can I delete the tags from myFeature branch?

Upvotes: -2

Views: 518

Answers (1)

LeGEC
LeGEC

Reputation: 52006

I'm not sure this answers your actual issue, but here is an answer to the question :

How do I list tags pointing at any commit in the history of myFeature branch ?

One way is to combine git rev-list and git for-each-ref --points-at :

git rev-list myFeature |\
  xargs -L1 git for-each-ref refs/tags --format="%(refname)" --points-at
  • git rev-list myFeature will list all commits in the history of myFeature
  • git for-each-ref refs/tags --format="%(refname)" --points-at xxx will list all the tags that point at commit xxx
  • xargs -L1 ... is one way to call the command on the right once for each line coming from the left

You should get a list formatted like this :

$ git rev-list myFeature | xargs -L1 git for-each-ref refs/tags --format="%(refname)" --points-at
refs/tags/SFDCxxxx1
refs/tags/SFDCxxxx2
refs/tags/SFDCxxxx3
 ...

As for deleting them :

Once you have checked that you listed only tags you want to delete, you can use this list to delete tags from the remote :

... | xargs git push origin -d

To delete tags locally, you need to either get rid of the leading refs/tags/, or use update-ref -d :

# one way : replace the '--format' option of 'git for-each-ref' :
... --format="%(refname:short)" ... | xargs git tag -d

# another way : feed 'refs/tags/SFDCxxx' references to 'update-ref -d' one by one
... | xargs -L1 git update-ref -d

Upvotes: 0

Related Questions