Remove commit for good

让人想犯罪 __ 提交于 2019-12-09 01:21:38

问题


I know there are thousands of threads for this question.

But I found out something really weird.

If you create a project on GitHub, do some commits.
Let's say commit 1, 2, 3, 4, 5.
Later, you realize you want to change something into commit 3.

As you were working in your own branch, no problem to rewrite history.

So let's do this: (based on this stackoverflow answer)

git rebase --interactive 'bbc643cd^'

// Modify 'pick' to 'edit' into interactive prompt and :
git commit --all --amend --no-edit
git rebase --continue
git push -f

Great! The mistake is corrected. The history has been rewritten, so the commit bbc643cd is now lkqjfhchc.
You can check the source on your GitHub and everything will have been updated.

But someone can still find it on GitHub!

Access the URL: https://github.com/your-nickname/your-project/commit/bbc643cd... (full commit hash) and you will find it!

How could we remove this commit for good?

Thanks for any help!


回答1:


I contacted Github staff from here : https://github.com/contact

Here's the answer (I couldn't do anything about it, no prune, no gc, etc)

Hey Maxime,

The commit was available because commits are not automatically deleted when they're removed from the history of a branch -- they're deleted when they're garbage collected. I just ran garbage collection for that repository manually and the commit should now return a 404.

Hope this helps.

Cheers, XXXXX

So you just have to wait or contact staff to force garbage collector in case you have the same problem !




回答2:


According to your additional comments :

You did everything as it should be.
The point is this: git never lose data unless you tell it to (whats known as gc - garbadge collector)

The files will remain there until they will gc will be called.

This is called dangling file

Dangling commit

A commit that isn't linked to any branch or tag either directly or by any of its ascendants.

You can see all the dangling references locally with this:

git fsck --full

The only way to get rid of it is to run gc

//
// !!!Caution:
// It will remove all your dangling files
git gc --aggressive --prune now

Here you can read some more about it.



来源:https://stackoverflow.com/questions/34582480/remove-commit-for-good

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!