git 如何删除 github gist 的特定修订版?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5912274/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:25:40  来源:igfitidea点击:

How to delete a specific revision of a github gist?

gitgithubrevisiongist

提问by Cyril N.

I created a Gist on GitHub and I saw informations I don't want anyone to see. I updated the file since, but everybody can still access the old revision of the file.

我在 GitHub 上创建了一个 Gist,我看到了我不想让任何人看到的信息。从那以后我更新了文件,但每个人仍然可以访问文件的旧版本。

Except deleting the Gist, is there a way to delete that particular revision definitely?

除了删除 Gist 之外,有没有办法明确删除该特定修订版?

I saw that I'm not the only one having that kind of problem (Git: delete a single remote revision) but I didn't manage to remove the revision. The process indicated here seems to help remove some files. I want to remove the whole revision.

我看到我不是唯一遇到这种问题的人(Git:删除单个远程修订版),但我没有设法删除修订版。此处指示的过程似乎有助于删除某些文件。我想删除整个修订版。

采纳答案by Tilman Vogel

Github has a help page about removing sensitive data:

Github 有一个关于删除敏感数据的帮助页面:

http://help.github.com/removing-sensitive-data/

http://help.github.com/removing-sensitive-data/

As gists are just git repositories, you should be able to locally clone your gist, do the clean-up there and do a forced push to overwrite the github version with the cleaned repo.

由于 gist 只是 git 存储库,您应该能够在本地克隆您的 gist,在那里进行清理并强制推送以使用已清理的存储库覆盖 github 版本。

Yes, after thinking about it: If <commit>is the commit you want to "remove", do

是的,经过深思熟虑:如果<commit>是您要“删除”的提交,请执行

 git rebase -i <commit>^

mark the line for <commit>as edit, save and quit.

将行标记为<commit>as edit,保存并退出。

git will set up the working directory to the state after you comitted <commit>. Fix the file, use git addand git commit --amendto fix the commit. Then do git rebase --continue. If the only thing, the next commit did, was to remove the sensitive data, it will probably be automatically dropped because it doesn't contain any changes after the now-amended commit.

git 会将工作目录设置为您提交后的状态<commit>。修复文件,使用git addgit commit --amend修复提交。然后做git rebase --continue。如果下一次提交所做的唯一一件事是删除敏感数据,它可能会自动删除,因为它在现在修改的提交之后不包含任何更改。

Then, do a git push -fto force the update (because it is now non-fast-forward, meaning it changes already published git history).

然后,执行 agit push -f强制更新(因为它现在是非快进的,这意味着它更改了已发布的 git 历史记录)。

回答by meesern

The accepted answer is good but a bit difficult to follow. Here's the same answer but a bit sweeter.

接受的答案很好,但有点难以理解。这是相同的答案,但有点甜。

As Tilman Vogel says, gists are just repositories and so this approach works for github repositories as well as gists.

正如 Tilman Vogel 所说,gist 只是存储库,因此这种方法适用于 github 存储库和 gist。

Let's assume that there is just one version that contains a password that you don't want to show. You've checked in the new version with the password removed and want to get rid of the previous version. You should be able to adapt this process if there are a number of commits showing the password.

假设只有一个版本包含您不想显示的密码。您已在删除密码的情况下签入新版本,并希望摆脱以前的版本。如果有多次提交显示密码,您应该能够调整此过程。

The first thing is that the repair has to be done on your local machine (not in github). To do this start by cloning the gist locally. The gist's page on github should show you how to create a private clone if you click on the private clone URL. Something like:

第一件事是修复必须在您的本地机器上完成(而不是在 github 中)。要做到这一点,首先要在本地克隆要点。如果您单击私有克隆 URL,github 上的要点页面应该会向您展示如何创建私有克隆。就像是:

git clone [email protected]:421xxx1.git gist-421xxx1

This gives you a local copy that you need to rebase (meaning muck around with the versions).

这为您提供了一个需要变基的本地副本(意味着与版本混为一谈)。

cd gist-421xxx1
git rebase -i eexxaa^

Where eeccaa is the (first) version containing the password. You can get this number from the gist page revisions column. The ^ is required. The command means 'let me change the verisons from eexxaa to the latest, interactively. The command opens up an editor populated with a command on each line for each version in the repo. The default command is 'pick' meaning 'use or keep this version'.

其中 eeccaa 是包含密码的(第一个)版本。您可以从要点页面修订列中获取此编号。^ 是必需的。该命令的意思是'让我以交互方式将版本从 eexxaa 更改为最新版本。该命令会打开一个编辑器,该编辑器在存储库中的每个版本的每一行上都填充了一个命令。默认命令是“pick”,意思是“使用或保留此版本”。

The first lines in the editor should look something like

编辑器中的第一行应该类似于

pick eexxaa    <- the version with the password
pick ffxxbb    <- the first version without the password

Change this to

将此更改为

pick eexxaa    
squash ffxxbb 

I.e. Change the word 'pick' to 'squash' on the version without the password. This will ask the rebase to squash the new (passwordless) version into the old (password carrying) one, essentially deleting version eexxaa. Obviously your versions will be other than eexxaa or ffxxbb don't literally use eexxaa or ffxxbb anywhere!

即在没有密码的版本上将单词“pick”更改为“squash”。这将要求 rebase 将新(无密码)版本压缩为旧(携带密码)版本,实质上是删除版本 eexxaa。显然,您的版本将不同于 eexxaa 或 ffxxbb,不要在任何地方使用 eexxaa 或 ffxxbb!

As @kand notes, you should squashevery version that contained the password.

正如@kand 所指出的,您应该squash每个版本都包含密码。

In the editor save and quit (if it's vi :x). The rebase should now open a new editor showing the commit messages for the two versions and asking for a single combined commit message. For a gist these messages are quite likely to be empty but you do need to put something in here or the rebase will abort. Type a message, save it and quit and the rebase should complete.

在编辑器中保存并退出(如果是 vi :x)。变基现在应该打开一个新的编辑器,显示两个版本的提交消息,并要求提供单个组合提交消息。对于一个要点,这些消息很可能是空的,但您确实需要在这里放一些东西,否则 rebase 将中止。输入一条消息,保存并退出,rebase 应该完成。

You now have a repository without the password-containing version. To get this back to the gist use:

您现在拥有一个没有包含密码的版本的存储库。要将其恢复到要点,请使用:

git push -f

This will force the changes onto the github repo. Hit refresh and you should be able to check in the browser that the offending version has gone from the revisions column on the right hand side.

这将强制更改到 github 存储库。点击刷新,您应该能够在浏览器中检查违规版本是否已从右侧的修订列中消失。

Thats it!

就是这样!

回答by Rafay

If you are not concerned about showing any of the revisions on the gist, you can do the following to eliminate all history and just show one revision.

如果您不关心在 gist 上显示任何修订,您可以执行以下操作以消除所有历史记录并仅显示一个修订。

git clone some-gist-repo
cd some-gist-repo
git rebase -i --root $tip

You would be able to see all the commits for that gist in your editor. Just pick the first one and replace everything else with sor squash. Once done, save and add a commit message and then do a force push to master like this and you are good.

您将能够在编辑器中看到该要点的所有提交。只需选择第一个并用s或替换其他所有内容squash。完成后,保存并添加一条提交消息,然后像这样强制推送到 master,你就很好了。

git push -f origin master

The only revision that would be visible is the addition of file(s) and thats it.

唯一可见的修订是添加文件,仅此而已。

回答by ralphtheninja

If you want to completely delete something from the repository you need to use git filter-branch.

如果要从存储库中完全删除某些内容,则需要使用 git filter-branch。

http://git-scm.com/docs/git-filter-branch

http://git-scm.com/docs/git-filter-branch

回答by ShunS

Adding to meesern's answer. When you try to squash or fixup and rebase--continue, you are required to add a comment or --allow-empty-message. This is time consuming, and somehow my commits did not go away from the gist's revision list by doing that way.

添加到 meesern 的答案。当您尝试压缩或修复和变基时 - 继续,您需要添加注释或--allow-empty-message. 这很耗时,而且不知何故,我的提交并没有通过这样做而脱离要点的修订列表。

I found a simpler solution: You can just delete the unnecessary commit lines on your rebase to-do list, :wq!, git rebase --continue, and git push -f.

我找到了一个更简单的解决方案:您可以删除 rebase 待办事项列表:wq!git rebase --continue、 和 中不必要的提交行git push -f