我在 GitHub 上创建了一个 Gist,并且看到了我不想让任何人看到的信息。
此后我更新了该文件,但每个人仍然可以访问该文件的旧版本。
除了删除要点之外,有没有办法彻底删除该特定修订版?
我发现我不是唯一一个遇到此类问题的人(Git:删除单个远程修订),但我没有设法删除该修订。
此处所示的过程似乎有助于删除一些文件。我想删除整个修订版。
I created a Gist on GitHub and I saw information I don't want anyone to see.
I updated the file since, but everybody can still access the old revision of the file.
Except deleting the Gist, is there a way to delete that particular revision definitely?
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.
发布评论
评论(8)
Github 有一个关于删除敏感数据的帮助页面:
http://help.github.com/removing- sensitive-data/
由于 gist 只是 git 存储库,因此您应该能够在本地克隆您的 gist,在那里进行清理,并强制推送以使用清理后的存储库覆盖 github 版本。
是的,考虑一下之后:如果
是您要“删除”的提交,请将
行标记为edit
,保存并退出。git 会将工作目录设置为您提交
后的状态。修复文件,使用 git add 和 git commit --amend 来修复提交。然后执行git rebase --Continue
。如果下一次提交所做的唯一事情是删除敏感数据,那么它可能会被自动删除,因为它在现在修改的提交之后不包含任何更改。然后,执行 git push -f 强制更新(因为它现在是非快进的,这意味着它更改了已发布的 git 历史记录)。
Github has a help page about 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.
Yes, after thinking about it: If
<commit>
is the commit you want to "remove", domark the line for
<commit>
asedit
, save and quit.git will set up the working directory to the state after you comitted
<commit>
. Fix the file, usegit add
andgit commit --amend
to fix the commit. Then dogit 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.Then, do a
git push -f
to force the update (because it is now non-fast-forward, meaning it changes already published git history).接受的答案很好,但有点难以遵循。这是相同的答案,但更甜蜜一些。
正如 Tilman Vogel 所说,gists 只是存储库,因此这种方法适用于 github 存储库和 gists。
假设只有一个版本包含您不想显示的密码。您已签入已删除密码的新版本,并且想要删除以前的版本。如果有大量提交显示密码,您应该能够适应此过程。
首先,修复必须在本地计算机上完成(而不是在 github 中)。为此,首先要在本地克隆要点。如果您单击私有克隆 URL,则 github 上的要点页面应该会向您展示如何创建私有克隆。类似于:
这为您提供了需要重新设置基准的本地副本(意味着对版本进行修改)。
其中 eeccaa 是包含密码的(第一个)版本。您可以从要点页面修订列中获取此数字。 ^ 是必需的。该命令的意思是“让我以交互方式将版本从 eexxaa 更改为最新版本”。该命令将打开一个编辑器,其中在存储库中的每个版本的每一行上都填充了一个命令。默认命令是“pick”,意思是“使用或保留此版本”。
编辑器中的第一行应类似于将
其更改为
Ie 在没有密码的版本上将单词“pick”更改为“squash”。这将要求变基将新(无密码)版本压缩到旧(带有密码)版本中,本质上是删除版本 eexxaa。显然,您的版本将不是 eexxaa 或 ffxxbb 以外的版本,不要在任何地方真正使用 eexxaa 或 ffxxbb!
正如 @kand 所指出的,您应该
压缩
包含密码的每个版本。在编辑器中保存并退出(如果是 vi :x)。变基现在应该打开一个新编辑器,显示两个版本的提交消息并要求单个组合提交消息。就要点而言,这些消息很可能是空的,但您确实需要在此处放置一些内容,否则变基将中止。输入一条消息,保存并退出,变基应该完成。
您现在拥有一个没有包含密码版本的存储库。要回到要点,请使用:
这将强制将更改写入 github 存储库。点击刷新,您应该能够在浏览器中检查有问题的版本已从右侧的修订列中删除。
就是这样!
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.
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:
This gives you a local copy that you need to rebase (meaning muck around with the versions).
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'.
The first lines in the editor should look something like
Change this to
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!
As @kand notes, you should
squash
every version that contained the password.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.
You now have a repository without the password-containing version. To get this back to the gist use:
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.
Thats it!
如果您不关心显示要点上的任何修订,您可以执行以下操作来消除所有历史记录并仅显示一个修订。
您将能够在编辑器中看到该要点的所有提交。只需选择第一个,然后用
s
或squash
替换其他所有内容。完成后,保存并添加提交消息,然后像这样强制推送到 master,就可以了。唯一可见的修订是添加文件,仅此而已。
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.
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
s
orsquash
. Once done, save and add a commit message and then do a force push to master like this and you are good.The only revision that would be visible is the addition of file(s) and thats it.
如果你想从存储库中完全删除某些内容,你需要使用 git filter-branch。
http://git-scm.com/docs/git-filter-branch
If you want to completely delete something from the repository you need to use git filter-branch.
http://git-scm.com/docs/git-filter-branch
@ 2022-03 进行了测试
许多解决方案基于
squash
方式。我只是说直接删除最后一个(或多个)提交
(没有压缩,不会生成新的提交版本),这可能有常见的情况。
删除提交解决方案
在
git rebase -i eexxaa^
步骤时 ,只需将最后一个不需要的提交标记为
drop
,然后保存。最后
git push -f
然后 drop 版本也会在 gist 页面中删除。
从哪里获取 gist 的 repo url ?
只需打开要点页面>复制浏览器地址栏中的网址,
使用 git clone $the_url ,它可以工作。
注意:使用 http(s) 还需要 github 访问令牌 而不是密码;
访问令牌只需要
gist
权限(可以强制推送)tested @ 2022-03
many solution based on
squash
way.I just say delete last one (or more) commits directly
(without squash, no new commit version generate), which may have common situation.
drop commit solution
when
git rebase -i eexxaa^
step,just mark last unwant commit as
drop
, save it.finally
git push -f
then the drop version also delete in gist page.
where get the repo url of gist ?
just open the gist page > copy url in broswer addressbar,
use
git clone $the_url
, it works.note: use http(s) also need github access token rather than password;
access token only need
gist
permission (can do force push)添加到 meesern 的答案。
当您尝试压缩或修复并重新设置基准--继续时,您需要添加注释或
--allow-empty-message
。这是耗时的,而且不知何故,我的提交并没有通过这种方式脱离要点的修订列表。我找到了一个更简单的解决方案:
您可以删除 rebase 待办事项列表中不必要的提交行,
:wq!
、git rebase --continue
和git push -f.
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.I found a simpler solution:
You can just delete the unnecessary commit lines on your rebase to-do list,
:wq!
,git rebase --continue
, andgit push -f
.我在这里尝试了其他答案,但有两个问题:
force
)。我通过首先在第一次提交时创建另一个分支来解决这两个问题,然后 cherry-picking< /a> 其余的提交一一提交,而不自动提交它们(以便我可以在提交之前编辑它们)。
之后,我将
master
分支重置为新分支:git switch master && git reset --hard temp
。在推送之前,我将遥控器更改为 SSH 版本:
git Remote set-url origin [email protected]:<>.git
然后,使用 git push --force 推送并更改修订要点。
I tried the other answers here but had two problems:
force
).I solved those two problems by first creating another branch on the first commit, and cherry-picking the rest of the commits one-by-one, without committing them automatically (so that I can edit them before commit).
After that, I reset the
master
branch to the new branch:git switch master && git reset --hard temp
.And before pushing, I changed the remote to the SSH version:
git remote set-url origin [email protected]:<<gist id>>.git
And then, using
git push --force
it pushed and changed the gist revisions.以前的答案都没有完全成熟或对我有用,所以我推出了自己的答案。在这里分享,以防它对任何人有用。脚本中有一些错误检查,但请检查它并检查您正在做什么,因为这确实有可能破坏数据。
保存下面的脚本并执行,提供 Gist 的 URL 作为参数。如果提供的 URL 具有特定修订版的路径,则该路径将用于变基,否则会将您的要点重置为“提示”——所有先前的提交都将被删除。
初始克隆后将会有一个暂停,以便您可以根据需要进行其他编辑。
gist-clean.sh
示例:
None of the previous answers were fully baked or working for me, so I rolled my own. Sharing it here in case it's useful to anyone. There is some error checking in the script, but please review it and check what you are doing, because this does have the potential to destroy data.
Save the script below and execute, supplying the URL to your Gist as the parameter. If the URL supplied has a path to a specific revision, that will be used to rebase, otherwise it will reset your gist to the "tip"—all previous commits will be removed.
There will be a pause after the initial clone so you can make additional edits if you want.
gist-clean.sh
Example: