-2

I recently did an interactive rebase to remove a specific commit from my repo. However, I can still see the details of the commit by using git show <commit hash>. How do I entirely remove the history of this deleted commit?

I asked "How to remove the history of a commit?", Not "How to remove a commit from git history". This is not a duplicate question. None of the suggestions provide a solution to my question.

Anurag Mondal
  • 57
  • 1
  • 6
  • Had that commit been pushed to a remote? – jonrsharpe Feb 02 '21 at 09:37
  • `git reflog expire --all BRANCH1 BRANCH2 && git prune --expire now` – phd Feb 02 '21 at 10:04
  • https://stackoverflow.com/search?q=%5Bgit%5D+%22remove+commit%22 – phd Feb 02 '21 at 10:04
  • I asked "How to remove the history of a commit?", Not "How to remove a commit from git history". This is not a duplicate question. None of the suggestions provide a solution to my question. – Anurag Mondal Feb 03 '21 at 10:47
  • 3
    What do you think "history of a commit" means? The only "history of a commit" that exists is the commit itself, and its children. Therefore, the only way to remove "the history of a commit" is to remove the commit. – Jonathan Hall Feb 03 '21 at 11:06
  • @Flimzy I already removed the commit but using `git show` I can still see the details of the commit. How do I remove those details? – Anurag Mondal Feb 04 '21 at 15:35
  • @jonrsharpe Yes – Anurag Mondal Feb 04 '21 at 15:36
  • @phd Tried already. Doesn't work – Anurag Mondal Feb 04 '21 at 15:37
  • 1
    That means something else (an open branch, for example) is still referencing it. – Jonathan Hall Feb 04 '21 at 15:47
  • Then removing it from GitHub means a request to their support, you *can't* do it yourself. See e.g. https://docs.github.com/en/github/authenticating-to-github/removing-sensitive-data-from-a-repository. – jonrsharpe Feb 04 '21 at 15:55
  • `git branch --contain `, `git tag --contain ` – phd Feb 04 '21 at 16:13
  • https://github.com/7Ragnarok7/DEDMAP Here's my repo if anyone wants to have a look. The hash of the commit which I am concerned about is: ab472 – Anurag Mondal Feb 05 '21 at 16:20
  • @Flimzy Yes, you are right. I have two tags in my master branch and using `git tag --contain ` lists both of the tags. How do I stop these tags from referencing it? Do I have to remove those tags and create new tags again? – Anurag Mondal Feb 05 '21 at 16:35
  • Yes, you need to remove the tags – Jonathan Hall Feb 05 '21 at 17:59
  • Thanks @Flimzy. It fixed the issue. However the name of the person who did that commit is still showing in the github contributor's list. Is there anyway to remove it from github? – Anurag Mondal Feb 07 '21 at 07:29

1 Answers1

0

If the commit is not in the history of any branch or tag you can do this:

git gc --aggressive

git gc is also run as a side-effect of some other git commands like push or pull so the commit should disappear automatically after some time.

mousetail
  • 7,009
  • 4
  • 25
  • 45