0

I accidentally committed some secret data in a private git repo. Fortunately it's only used by a small number of people, so I looked up a guide on how to remove a commit and I decided to remove my entire branch (it's ok, I can redo the work).

$ git reset --hard <last-good-commit-hash>
$ git push -f master

I check the git logs for my bad commit id, and it's gone! I remove my repo and re-clone, and it looks like everything is good. However, I can still access the secret data at https://gitlab.com/group/project/-/commit/bad-commit-hash! Furthermore, I can do

$ git clone git@gitlab.com:group/project.git
$ cd project
$ git checkout <bad-commit-hash>
fatal: reference is not a tree: <bad-commit-hash>
$ git fetch --depth=1 git@gitlab.com:group/project.git <bad-commit-hash>
remote: Enumerating objects: 18, done.
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), 2.59 KiB | 2.59 MiB/s, done.
From gitlab.com:group/project
 * branch            <bad-commit-hash> -> FETCH_HEAD
$ git checkout <bad-commit-hash>
Note: switching to '<bad-commit-hash>'.

along with some text about being in a detached HEAD state. If I instead try to pull the same trick on a freshly-cloned local copy of the repo, it doesn't work:

$ git fetch .git <bad-commit-hash>
fatal: git upload-pack: not our ref <bad-commit-hash>
fatal: remote error: upload-pack: not our ref  <bad-commit-hash>

I don't understand how this is possible? How can I clone the repo and the commit doesn't exist, but I can still fetch the commit from the same repo. Is this a gitlab-specific issue?

Any help would be greatly appreciated. At this point I'm looking at rotating the key and/or deleting the entire project and re-creating from my local repo.

sconstable
  • 23
  • 3
  • "*How can I clone the repo and the commit doesn't exist, but I can still fetch the commit from the same repo.*" Because the commit is still in the database. It'll be removed on garbage collecting after [some period](https://git-scm.com/docs/git-gc#Documentation/git-gc.txt-gcpruneExpire), defaul is 2 weeks. "*Is this a gitlab-specific issue?*" No, it's generic GIt. One can [contact Github support](https://stackoverflow.com/a/32840254/7976758) to manually run garbage collector to remove offending commits. Not sure about Gitlab. Try to contact support anyway if you worry. – phd Dec 02 '21 at 11:27
  • @phd thank you for this advice, I am contacting them now – sconstable Dec 02 '21 at 14:30
  • 1
    On GitLab, each project has a "housekeeping" option which includes garbage collection. – Arty-chan Dec 05 '21 at 06:32
  • 2
    Does this answer your question? [Remove sensitive files and their commits from Git history](https://stackoverflow.com/questions/872565/remove-sensitive-files-and-their-commits-from-git-history) – Arty-chan Dec 05 '21 at 06:34

0 Answers0