2/11/2024 0 Comments Delete git tag from remote![]() ![]() git checkout tags/v1.0 -b v1.0-branch To find the remote tags: git ls-remote -tags origin Create a tag with the given tag message. git checkout tags/tag-name -b branch-name eg as mentioned below. ![]() Notice we’re using the xargs’ input through the percentage char (%) here. In order to checkout a git tag, you would execute the following command. We tell to sh to read the execution from a string thanks to the -c argument.įinally, inside the string we execute the git commands to delete the tag remotely first, and then locally as well. Then, we use xargs to use the input through the percentage char (%) and combine it with the sh command. xargs -I % sh -c "git push origin :% git tag -d % ".Here we use awk for filtering all the matching versions with the regular expression defined in the SEMVER variable. Showing the available local tags in our local git repo. This one-line-command actually does the following things:ĭeclaring the SEMVER variable and for later use inside the awk command. \* / " | xargs -I % sh -c "git push origin :% git tag -d % " This protects us against possible shell injection.īe careful, as running this exact script inside your repository will delete all tags created before. Note how we invoke the system method with an array of arguments for those calls that require input. It can look pretty complex, but most of it is just string manipulation to get the date and tags of each line outputted by the git log command, and storing old tags in the old_tags array. The get_old_tags method might stand out a bit here. Git Delete Remote Tag If you push a wrong tag to a remote repository, it isn't enough to delete it only locally. This Ruby script should be pretty straightforward. Run the following command: git tag -l The output lists all existing tags and shows that the previously deleted tags no longer exist in the repository. `git fetch -prune origin +refs/tags/*:refs/tags/*` System("git", "push", "-delete", "origin", *batch) Get_old_tags(CUT_OFF_DATE).each_slice(100) do |batch| # delete all tags on the remote that were created before the CUT_OFF_DATE `git log -tags -simplify-by-decoration -pretty="format:%ai %d"` # CUT_OFF_DATE needs to be of YYYY-MM-DD format This is why we are going to make use of a Ruby script here. Unfortunately, git doesn’t have any built-in functionality for accomplishing this. While the cut-off tag approach works great in a lot of scenarios, sometimes you just want to delete all tags that were created before a given cut-off date instead. Piping this output to xargs git push -delete origin will then remove these tags from Github. Looking back at our sequence of commands above, it should be clear that this will cause us to obtain all tags that do not have the release-5 tag as an ancestor. In other words, it causes comm to return just those lines that only appear in file 1. The -23 flag tells comm to suppress any lines that are unique to file 2, as well as any lines that appear in both files. ![]() comm -23 <(command to act as file 1) <(command to act as file 2) | xargs git push -delete origin Luckily, we can avoid having to create any actual files by relying on process substitution instead. The comm command is used to compare two sorted files line by line. Git fetch -prune origin +refs/tags/*:refs/tags/* # delete all local tags that are no longer present on the remote # delete all tags on the remote that do not have the release-5 tag as an ancestorĬomm -23 <(git tag | sort) <(git tag -contains release-5 | sort) | xargs git push -delete origin The remainder of this section will focus on explaining this command. Most of these commands are pretty self-explanatory, except for the one in the middle. The sequence of commands below deletes all tags that do not have the release-5 tag as an ancestor. In this scenario, all you have to do is tag the merge commit and then use this as the cut-off tag. This is especially useful for when you have just merged a new feature, and now you want to delete all tags that were created before this merge. All tags that can trace their ancestry back to this cut-off tag will be allowed to remain. This approach has us specify a cut-off tag. In this article, we’ll look at two approaches to rid yourself of these old tags. It is at this point, when you have well in excess of tens of thousands of tags, that a call to action tends to be made. This onslaught of tags tends to be tolerated until it starts impacting git performance. It’s very easy for a Github repository to accumulate lots of tags over time. So the syntax representing the command for removing a remote branch looks like this: git push origin -d branch-name. Finding and deleting old tags in a Github repository Jul 18, 2014 To completely remove a remote branch, you need to use the git push origin command with a -d flag, then specify the name of the remote branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |