git 删除 Github 提交历史
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7048690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete Github commit history
提问by Manish Burman
Is there anyway for me to delete my github commit history? I don't want to lose all my commits, just the last 10 or so that were pushed to github. I can't seem to figure out how to do this.
无论如何我可以删除我的github提交历史吗?我不想丢失我所有的提交,只是最后 10 个左右被推送到 github 的提交。我似乎无法弄清楚如何做到这一点。
回答by matthewdaniel
Just pick the hash you want to go back to and in your clone do:
只需选择您想要返回的哈希值,然后在您的克隆中执行以下操作:
git reset --hard hash#
git push -f origin branch
where branch
is the name of the branch you want to push. Voilà. Be carefully with the force push. You may want to copy your working directory until you are familiar with it.
branch
您要推送的分支的名称在哪里。瞧。小心用力推动。您可能希望复制您的工作目录,直到您熟悉它为止。
回答by Kit Ho
If you want to do this, you can use HEAD~10
如果你想这样做,你可以使用 HEAD~10
git reset --hard HEAD~10
git push -f origin master
It is not recommended to do delete server commit history, especially: if you have a team of people working on this repo.
不建议删除服务器提交历史记录,尤其是:如果您有一组人员在处理此存储库。
If you have a team of people working on this, I would recommend to fall back by adding another commit that undo your code you don't want.
如果你有一个团队在做这件事,我建议你通过添加另一个提交来撤消你不想要的代码。
回答by Droogans
I had uploaded allof my files to my first github project, including some settings files with secret keys. I had to go back and remove all the versions that were included before I added my .gitignore
file, and deleted all settings files from my project's cache.
我已将所有文件上传到我的第一个 github 项目,包括一些带有密钥的设置文件。在添加.gitignore
文件之前,我必须返回并删除包含的所有版本,并从项目缓存中删除所有设置文件。
gedit ./.git/logs/HEAD
gedit ./.git/logs/HEAD
Find the 40-character SHA hash of the 'new root' you wish to delete everything prior to. Copy it to the clipboard and close it. (You may or may not use gedit
, a default text editor for linux).
找到您希望删除之前所有内容的“新根”的 40 个字符的 SHA 哈希。将其复制到剪贴板并关闭它。(您可能会也可能不会使用gedit
Linux 的默认文本编辑器)。
$> gedit ./.git/info/grafts
$> gedit ./.git/info/grafts
Paste the SHA here. Go to your project's directory.
将 SHA 粘贴到此处。转到您的项目目录。
$> cd ../..
$> cd ../..
$> git filter-branch
$> git filter-branch
Force the push to the master, otherwise it will block your attempt to erase your history.
强制推送到 master,否则它会阻止您擦除历史记录的尝试。
$> git push --force -u origin master
$> git push --force -u origin master
Delete your grafts
file.
删除您的grafts
文件。
$> rm ./.git/info/grafts
$> rm ./.git/info/grafts
NEVERMIND
没关系
Well, my answer is only half the battle. My public activity RSS feed still has links to all the diffs that detail the very information I wanted to remove. Apparently, there is no way to delete this, but you should probably read Change your Password, and update any sensitive data you may have accidentally uploaded.
好吧,我的回答只是成功了一半。我的公共活动 RSS 提要仍然有指向所有差异的链接,这些差异详细说明了我想删除的信息。显然,没有办法删除它,但您可能应该阅读Change your Password,并更新您可能不小心上传的任何敏感数据。
回答by Leo
With Gitinstalled, you could also right-click your repository folder - Git GUI Here.
随着Git的安装,你也可以用鼠标右键单击您的存储库文件夹- Git的GUI这里。
Select Repository- Visualize All Branch History.
选择Repository- Visualize All Branch History。
Right-click the desired commit - Reset master branch history to here.
右键单击所需的提交 - 将主分支历史记录重置到此处。
Now you have 3 options:
现在你有 3 个选择:
Once chosen, select File- Reload.
选择后,选择File- Reload。
Managed to figure this out after selecting Revert on a commit in GitHub Desktop, then Revert again so we're back to the original code, then simply wishing to clean up these couple Revert commits.
在GitHub Desktop 中选择 Revert on a commit 后设法解决了这个问题,然后再次 Revert 所以我们回到原始代码,然后只是希望清理这对夫妇 Revert 提交。