0

I pushed an unwanted commit, and now I want to remove it. For its removal, I have used :

git rebase -p --onto SHA^ SHA

So now it looks like I have removed the unwanted pushed commit, and it doesn't show itself in git log. ( But I can see it in git reflog).

However, I can still reach the commit by its SHA and see the files in URL.

Even though they are not seen in /commits/all. Also, I can see that in my recent activities, I have removed the commit with its SHA.

But again, I can reach to it by URL : /commits/all/SHA_of_removed_commit

How can I remove this commit and all its contents, so that it would be impossible to see it even in URL?

EDIT:

I have tried : git reset --hard SHA_that_I_am_happy_with but it did not work. I can still connect to unwanted one in URL. I have tried to run git gc --aggressive but it also did not stop me seeing the unwanted commit files in its URL.

Also, i can still see it when I say :

git show unwanted_pushed_commit_SHA

ANOTHER EDIT :

I have run :

git fsck --no-reflogs
git reflog expire --expire-unreachable=now --all
git gc --prune=now

After all these, git show unwanted_commit_SHA says :

fatal:ambiguous argument 'unwanted_commit_SHA' : unknown revision or path not in the working tree.

But I can still see it via its URL..

How can I finally get a 404 page when I type URL of repository/commits/unwanted_commit_SHA?

bapors
  • 887
  • 9
  • 26

2 Answers2

1

You removed the commit from your Git's history, but as you saw, the commit was in fact still in your repository, protected from garbage collection, until you ran:

git reflog expire --expire-unreachable=now --all

and was not subsequently garbage collected until you forced that to happen as well.

The reason you can see this commit by URL on some other machine that has its own Git repository is that the other machine still has the commit in its repository. This commit may be reachable from some branch name (may be in history), or may not (if you have force-pushed to adjust its history). The commit must still be in their repository, maybe protected by a reflog entry, or maybe just not yet garbage collected, so that they can still serve the contents of the commit.

Unless you have a way to make them expire reflogs and run garbage collection, your only recourse at this point is to wait for them to expire and garbage collect on their own.

torek
  • 448,244
  • 59
  • 642
  • 775
  • Thank you for your amazing reply. If I understand it right, this command will force it to be a garbage? But where do I specify its SHA? And, it is a private repository, so I assume people did not fork it.. – bapors Feb 15 '18 at 21:21
  • How can I make them expire? And, I have checked the raw commit of this unwanted commit, and I could not find couple sensitive files that made me want to remove all commit. Is it possible that you can check this question of mine? I would appreciate it : https://stackoverflow.com/questions/48797569/github-file-removal-after-push/48800806?noredirect=1#comment84619970_48800806 – bapors Feb 15 '18 at 21:26
  • If you pay money to some service (like BitBucket or GitHub) you could perhaps expect them to offer a "fast expire and clean away" feature. If you are using their free service, you can still *ask* them (via whatever contact channels you have) but I'm not sure how much service you can expect... – torek Feb 16 '18 at 02:34
0

/* Hard reset will reset to the hash what you have set and the changes you made to the file wont be restored */

git reset --hard hash_value

/* Soft reset will reset to the hash what you have set and the changes you made to the file will be restored and if you want you can push it again */

git reset --soft hash_value

As per your requirement you must go for hard reset.

Channaveer Hakari
  • 2,769
  • 3
  • 34
  • 45
  • I have tried it. It only changed the output in git log. But I can still connect to the removed SHA with git show – bapors Feb 15 '18 at 11:36
  • Since git will store all the commits in the form of snapshots with HASH value to reference it. The HASH what you have can be referenced at any given point of time. Even if you delete the file and want to restore it that you can do that by the HASH – Channaveer Hakari Feb 15 '18 at 11:38