Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a developer irreversibly damage git repo?

Tags:

git

There is a git repository with master branch and several developers are using it (they don't have access to the git-server but can push to the master branch). My question is: Can a developer anyhow irreversibly "damage" (delete files...) the repository?

For example, a developer can delete last 10 commits:

git reset --hard HEAD~10
git push -f

Is there a way to restore the data in this case (assuming no one has those last 10 commits locally)? If so, is there any other method how to make irreversible changes to the repo?

like image 337
Martin Heralecký Avatar asked Oct 18 '25 21:10

Martin Heralecký


2 Answers

“Irreversible” is always kind of difficult to judge. Assuming that the developer is not the only developer on that repository, we can assume that there are other developers who also have a local repository—which is a full copy—and as such can always restore lost changes.

But in general, yes, if the remote server does not reject such actions, then one could potentially destroy the whole repository. Some hosting solutions offer protections against this (not meant against a malicious use, but rather to avoid accidents), where you can configure force pushes to be rejected. But force pushing is just one thing; one can actually just delete branches on a remote using git push -d origin branch. So you would need protection against deleting branches too (at least the critical ones, like master).

But let’s assume that all this goes through for some reason, and someone manages to force push a reference to the repository that makes certain commits unreachable. Assuming a default bare repository—which many solutions still use under the hood—the same things apply as with any local repository: Objects are not immediately deleted but just become unreachable. Objects being unreachable makes them subject for garbage collection which might delete them then permanently. So if the garbage collection has not run on the remote server, the objects might still be there.

The general rule though still applies: Make backups. For Git, this can be as simple as having a local clone updated regularly.

like image 85
poke Avatar answered Oct 21 '25 12:10

poke


I developed one day and a blackout killed my repo. It was an irreversible damage, becouse I didn't pushed it to private git server/github/gitlab, becouse I was lazy and I said to myself, that "tommorow I will do it". Luckily only the .git was dead, the code itself wasn't damaged. I reinit-ed the git and right after that I made a private repo on gitlab.

So my answer: If you don't make backups on a git server anything can damage that repo: coffee/coke/beer in notebook, the cat lies on your keyboard, even a ten floor fall from your flat after a windows crash

like image 42
Feralheart Avatar answered Oct 21 '25 11:10

Feralheart