Deleting
things in remote repository
As with forced pushes,
things in remote repositories must be deleted with extreme precaution. Before
deleting anything, every collaborator should be informed about it.
Actually, when we are
pushing commits, branches, etc., we are pushing them to a ref destination, but
we don’t have to specify the destination explicitly.
The explicit syntax is the
following:
git push origin <source>:<destination> |
So, the way of deleting
remote things is updating the refs to prior states, or pushing “nothing”.
Let’s see how to do it for
every case.
Deleting
commits
This is just the same as
deleting commits locally, for example, to delete the last two commits:
git push origin HEAD~2:master --force |
If we are using HEAD to
refer the commits to remove, we must ensure that it’s located on the same
branch as remote.
Note that these pushes have
to be forced too.
Deleting
branches
This is quite simple, is
just about pushing “nothing”, as said before. The following would remove dev branch
from remote repository:
git push origin :dev |
Remote branches should be removed when the local branch is removed.
Deleting
tags
As same as with branches, we
have to push “nothing”, e.g.:
git
push origin --tags :v1.0
|
No comments:
Post a Comment