Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove accidentally pushed data from Gitlab merge request

Tags:

git

gitlab

The problem is simple: one person pushed some unnecessary (and possibly private) info to origin on Gitlab. I need to remove it.

I understand how to change history in git, and how to make it be just like I want it to be. So I actually cleaned the history and force pushed it to the origin.

But the problem is that there is a merge request for this branch which collects all pushed versions of this branch (including this unnecessary info). So I decided to remove this merge request. It is not such trivial task (it can't be done through GUI), but after some search I found that this can be done through Gitlab API like this: curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/4/merge_requests/85 (look https://docs.gitlab.com/ee/api/merge_requests.html#delete-a-merge-request).

After that I ran "Housekeeping" from Project Settings on Gitlab which should do garbage collecting, but repository size haven't changed. I checked and yes - bad commits are still reachable by https://gitlab.com/<PROJECT>/commit/<HASH>. So it seems there are other things which don't allow these commits to be removed.

What should I do to prevent possible private info leak and to shrink repository from origin's ~130MB to my local .git/ ~30 MB.

P.S. I know about hardcore solution with creating new project and importing old one to it - it is not what I want.

P.P.S. I use Gitlab-hosted server so I can't (or can I?) just open ssh console and remove some files / database entrances manually.

UPD. Through API I got list of origin commits (https://docs.gitlab.com/ee/api/commits.html#list-repository-commits). Bad commits were not in this list, so this list should be identical to my local commit list.

like image 967
Dmitry Avatar asked Aug 20 '26 15:08

Dmitry


1 Answers

OK. I already said about my previous attempts in question. Also I tried local gc and reset --hard HEAD^ & push -f tricks from this answer: https://stackoverflow.com/a/37253227/4034402

And some days after (I don't know actually when), my repo size became 37Mb! Though after going by direct link to the commit, I still was able to get all these purged files. So it is only partial solution, but I decided to post it here for anyone interested. Also, I don't know which steps were necessary for achieving this partial solution and which were not.

like image 84
Dmitry Avatar answered Aug 22 '26 04:08

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!