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

发布于 2024-11-05 05:12:56 字数 286 浏览 1 评论 0 原文

我在 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

水染的天色ゝ 2024-11-12 05:12:56

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

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

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

是的,考虑一下之后:如果 是您要“删除”的提交,请将

 git rebase -i <commit>^

行标记为 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", do

 git rebase -i <commit>^

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

git will set up the working directory to the state after you comitted <commit>. Fix the file, use git add and git commit --amend to 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.

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

空心空情空意 2024-11-12 05:12:56

接受的答案很好,但有点难以遵循。这是相同的答案,但更甜蜜一些。

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

假设只有一个版本包含您不想显示的密码。您已签入已删除密码的新版本,并且想要删除以前的版本。如果有大量提交显示密码,您应该能够适应此过程。

首先,修复必须在本地计算机上完成(而不是在 github 中)。为此,首先要在本地克隆要点。如果您单击私有克隆 URL,则 github 上的要点页面应该会向您展示如何创建私有克隆。类似于:

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

这为您提供了需要重新设置基准的本地副本(意味着对版本进行修改)。

cd gist-421xxx1
git rebase -i eexxaa^

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

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

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

其更改为

pick eexxaa    
squash ffxxbb 

Ie 在没有密码的版本上将单词“pick”更改为“squash”。这将要求变基将新(无密码)版本压缩到旧(带有密码)版本中,本质上是删除版本 eexxaa。显然,您的版本将不是 eexxaa 或 ffxxbb 以外的版本,不要在任何地方真正使用 eexxaa 或 ffxxbb!

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

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

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

git push -f

这将强制将更改写入 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:

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'.

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!

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:

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.

Thats it!

中性美 2024-11-12 05:12:56

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

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

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

git push -f origin 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.

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 s or squash. Once done, save and add a commit message and then do a force push to master like this and you are good.

git push -f origin master

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

无名指的心愿 2024-11-12 05:12:56

如果你想从存储库中完全删除某些内容,你需要使用 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

晨曦÷微暖 2024-11-12 05:12:56

@ 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)

久伴你 2024-11-12 05:12:56

添加到 meesern 的答案。
当您尝试压缩或修复并重新设置基准--继续时,您需要添加注释或--allow-empty-message。这是耗时的,而且不知何故,我的提交并没有通过这种方式脱离要点的修订列表。

我找到了一个更简单的解决方案:
您可以删除 rebase 待办事项列表中不必要的提交行,:wq!git rebase --continuegit 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, and git push -f.

少女情怀诗 2024-11-12 05:12:56

我在这里尝试了其他答案,但有两个问题:

  1. 我无法重新设置它,我认为这是因为存储库的提交没有消息。
  2. 我无法推动它(是的,用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:

  1. I couldn't rebase it, I think it was because the repository is with commits without messages.
  2. I couldn't push it (yes, with 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.

尛丟丟 2024-11-12 05:12:56

以前的答案都没有完全成熟或对我有用,所以我推出了自己的答案。在这里分享,以防它对任何人有用。脚本中有一些错误检查,但请检查它并检查您正在做什么,因为这确实有可能破坏数据。

保存下面的脚本并执行,提供 Gist 的 URL 作为参数。如果提供的 URL 具有特定修订版的路径,则该路径将用于变基,否则会将您的要点重置为“提示”——所有先前的提交都将被删除。

初始克隆后将会有一个暂停,以便您可以根据需要进行其他编辑。

gist-clean.sh

#!/usr/bin/env bash

BASE_URL='gist.github.com'
GHUSER=$(git config --get user.name 2>/dev/null)

_usage() {
cat <<EOF

Reset a GitHub gist to clean up or remove sensitive information
usage: ${0##*/} <gist-url>

  if the URL supplied contains a revision ID (hash),
  then that revision will be used as the base.

  to get URLs to specific revisions:
    - browse to the gist on ${BASE_URL}${GHUSER:+/$GHUSER}
    - click "Revisions"
    - locate the revision you want to base from
    - click the 3 dots next to the filename -> "View file"
    - copy the URL

EOF
}

case $1 in
    -h|--help|'') _usage; exit;;
esac

[[ -n $1 ]] || { echo "supply a gist URL"; exit; }
[[ -n $GHUSER ]] || { echo 1>&2 "couldn't fetch GitHub username"; exit 1; }

if [[ $1 =~ ^https://${BASE_URL}/${GHUSER}/([a-f0-9]{32,40})/?([a-f0-9]{32,40})? ]]; then
    GIST_URL=${BASH_REMATCH[0]}
    GIST_ID=${BASH_REMATCH[1]}
    REV_HASH=${BASH_REMATCH[2]}
    CLONE_URL="https://${BASE_URL}/${GIST_ID}.git"
    TEMP_DIR="/tmp/gist${GIST_ID}"
    rm -rf "${TEMP_DIR}" 2>/dev/null
    mkdir -p "${TEMP_DIR}"
    if ! git clone "${CLONE_URL}" "${TEMP_DIR}" ; then
        exit 1
    fi
    cd "${TEMP_DIR}" || exit 1
    if [[ -n ${REV_HASH} ]]; then
        git reset --hard "${REV_HASH}"
    fi
    BRANCH=$(git symbolic-ref --short HEAD)
    cat <<-EOF
    ┌──────────────────────────────────────┐
    │                                      │
    │ PAUSED - YOU CAN NOW EDIT THE FILES  │
    │                                      │
    │           !!! WARNING !!!            │
    │                                      │
    │ ALL CONTENTS OF THE REMOTE GIST WILL │
    │  BE REPLACED BY THE LOCAL COPY, AND  │
    │     ALL REVISIONS WILL BE LOST!      │
    │                                      │
    └──────────────────────────────────────┘
    EOF
    read -r -p 'press <ENTER> to continue or ⌃c to ABORT '
    rm -rf .git
    git init
    git add .
    git commit -m 'initial commit'
    git remote add origin "[email protected]:${GIST_ID}.git"
    git push --set-upstream origin "$BRANCH" --force
    cd ..
    rm -rf "${TEMP_DIR}"
    open "${GIST_URL}"
else
    echo 1>&2 "does not appear to be a valid gist URL"
    exit 1
fi

示例:

./gist-clean.sh https://gist.github.com/your-git-username/f184a9c638b75525a65b3e1a7298e6d7/30e87b313bdba9a4bd92746418217ddda958b8cd

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

#!/usr/bin/env bash

BASE_URL='gist.github.com'
GHUSER=$(git config --get user.name 2>/dev/null)

_usage() {
cat <<EOF

Reset a GitHub gist to clean up or remove sensitive information
usage: ${0##*/} <gist-url>

  if the URL supplied contains a revision ID (hash),
  then that revision will be used as the base.

  to get URLs to specific revisions:
    - browse to the gist on ${BASE_URL}${GHUSER:+/$GHUSER}
    - click "Revisions"
    - locate the revision you want to base from
    - click the 3 dots next to the filename -> "View file"
    - copy the URL

EOF
}

case $1 in
    -h|--help|'') _usage; exit;;
esac

[[ -n $1 ]] || { echo "supply a gist URL"; exit; }
[[ -n $GHUSER ]] || { echo 1>&2 "couldn't fetch GitHub username"; exit 1; }

if [[ $1 =~ ^https://${BASE_URL}/${GHUSER}/([a-f0-9]{32,40})/?([a-f0-9]{32,40})? ]]; then
    GIST_URL=${BASH_REMATCH[0]}
    GIST_ID=${BASH_REMATCH[1]}
    REV_HASH=${BASH_REMATCH[2]}
    CLONE_URL="https://${BASE_URL}/${GIST_ID}.git"
    TEMP_DIR="/tmp/gist${GIST_ID}"
    rm -rf "${TEMP_DIR}" 2>/dev/null
    mkdir -p "${TEMP_DIR}"
    if ! git clone "${CLONE_URL}" "${TEMP_DIR}" ; then
        exit 1
    fi
    cd "${TEMP_DIR}" || exit 1
    if [[ -n ${REV_HASH} ]]; then
        git reset --hard "${REV_HASH}"
    fi
    BRANCH=$(git symbolic-ref --short HEAD)
    cat <<-EOF
    ┌──────────────────────────────────────┐
    │                                      │
    │ PAUSED - YOU CAN NOW EDIT THE FILES  │
    │                                      │
    │           !!! WARNING !!!            │
    │                                      │
    │ ALL CONTENTS OF THE REMOTE GIST WILL │
    │  BE REPLACED BY THE LOCAL COPY, AND  │
    │     ALL REVISIONS WILL BE LOST!      │
    │                                      │
    └──────────────────────────────────────┘
    EOF
    read -r -p 'press <ENTER> to continue or ⌃c to ABORT '
    rm -rf .git
    git init
    git add .
    git commit -m 'initial commit'
    git remote add origin "[email protected]:${GIST_ID}.git"
    git push --set-upstream origin "$BRANCH" --force
    cd ..
    rm -rf "${TEMP_DIR}"
    open "${GIST_URL}"
else
    echo 1>&2 "does not appear to be a valid gist URL"
    exit 1
fi

Example:

./gist-clean.sh https://gist.github.com/your-git-username/f184a9c638b75525a65b3e1a7298e6d7/30e87b313bdba9a4bd92746418217ddda958b8cd
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文