2

Is it possible to "unlink" commit from tag? What I want is, I want to delete binary branch which have tags in it as shown below;

master ----A----B----C----D
binary ----V----W----X----Y
            \    \    \    \
           tag1  tag2  tag3  tag4

I tried to delete it by $ git push origin :binary.

This command deletes binary branch from remote server but the repository size is the same as before.

I assume it is because the tags are attached onto V W X Y commits.

How can I completely remove binary branch and it's contents without deleting tags?

Dorr
  • 577
  • 1
  • 8
  • 22
  • If those are commits are referenced by other branches, then Git will retain them even if you delete the `binary` branch. Even if the commits are _not_ referenced anywhere else, they might still be in the reflog for some time. Have a look [here](http://stackoverflow.com/questions/3765234/listing-and-deleting-git-commits-that-are-under-no-branch-dangling) to read about garbage collection in Git. – Tim Biegeleisen Jul 25 '16 at 09:04

2 Answers2

3

Answer is no (if you pushed tags already) and "yes, sort-of" (if these tags exist only in your local repository).

Git tags are merely "pointers" to commits. In other words - content of tag is id of certain commit (do $ cat .git/refs/<path to some tag> to see for yourself). You can't change it - best you can do is remove tag and create new.

If you pushed tags, then it's over - you can't remove them any more (you can delete them from remote repo, but that won't remove them from users' repositories).

Melebius
  • 6,183
  • 4
  • 39
  • 52
Patryk Obara
  • 1,847
  • 14
  • 19
2

Tags are attached to commits. Deleting a commit without deleting the tags attached to it doesn't make sense. Assuming it is possible, the tags remain orphan and useless.

but the repository size is the same as before.

Assuming the commits you delete are not referred from other objects (tags, branches, merge commits) and their content can be safely dropped, the repository size doesn't change immediately. You have to force it to run its garbage collection routine.

For the local repository this can be accomplished by running git gc. I don't know how one could trigger a garbage collection on a remote repository.

axiac
  • 68,258
  • 9
  • 99
  • 134