0

I declined some PR from bitbucket and remove branch for this PR, but one commit from this branch still exists (I could checkout it by its hash). Is a way to remove commit by its hash without ability to checkout it later? I could call it "finally", without ability to recover. Thanks!

malcoauri
  • 11,904
  • 28
  • 82
  • 137
  • What I understood is that you 1) declined a PR because the source branch had a bad commit 2) want to now get rid of said commit on the feature branch 3) then recreate a PR without bad commit. Is it what you described? – Romain Valeri Dec 24 '19 at 17:08
  • Does this answer your question? [How to completely remove a commit from git history](https://stackoverflow.com/questions/19914510/how-to-completely-remove-a-commit-from-git-history) – phd Dec 24 '19 at 17:15
  • https://stackoverflow.com/search?q=%5Bgit%5D+completely+remove+local+commit – phd Dec 24 '19 at 17:15
  • Note that in general, there is no reason to bother with trying to get Git to reclaim a commit that is accessible only by hash ID. These commits won't be *visible* to normal use, so no one will use them. If you're trying to get rid of them because they contain sensitive data (e.g., passwords), it's probably too late: the sensitive data are probably already copied elsewhere and getting *this* Git to GC the commit won't suffice anyway. – torek Dec 24 '19 at 20:10

1 Answers1

0

Beside aggressively gc/pruning your repository, another simple option is to re-clone your repository.

You will get only the official current pushed history.

As commented, this does not mean anyone might have cloned the PR branch before you removed it, and might push back later that commit.

But at least, locally and for now, anyone (including you) cloning the repository won't be able to checkout (or using the new command: "restore") that commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250