如何编辑过去的 git 提交以从提交日志中删除我的密码?

发布于 2024-12-20 05:07:11 字数 318 浏览 4 评论 0原文

我的问题:使用 https:// URL 时,cygwin git 似乎没有正确提示输入凭据,因此我在 URL 中使用了用户名和密码。不幸的是,当我执行“get pull”时,它会自动提交一条包含完整 URL(包括密码)的消息。直到我推送更改后我才注意到这一点。

如何编辑旧的提交消息以消除 URL 中的密码?

我的共享 git 存储库位于我自己的服务器上。如有必要,我可以对回购进行手术。

关于如何更改我的配置(即不使用 Cygwin,不使用 https)的说明是不必要的——我正在尝试处理已经完成的事情。

是的,我可以并且将会烧掉密码,但我仍然想修复它。

My problem: cygwin git doesn't seem to correctly prompt for credentials when using https:// URLs, so I used username and password in the URL. Unfortunately when I did a "get pull" it auto-commited a message with the full URL including password. I didn't notice this until after I had pushed the changes.

How do I edit old commit messages to eradicate the password in the URL?

My shared git repo is on my own server. I can do surgery on the repo if necessary.

Instructions on how to change my configuration (i.e. don't use Cygwin, don't use https) are unnecessary -- I'm trying to deal with what is already done.

Yes, I can and will burn the password but I'd still like to fix it.

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

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

发布评论

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

评论(3

╰ゝ天使的微笑 2024-12-27 05:07:11

要从 git 存储库及其历史记录中完全删除文件,请使用以下命令。

# Check out the remote repo
git clone git://host/path/repo.git
cd repo

# Clobber the file in your checkout
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch file-to-purge.txt' --prune empty --tag-name-filter cat -- --all

# Make sure you don't accidentally commit the file again
echo file-to-purge.txt >> .gitignore
git add .gitignore
git commit -m "Prevent accidentally committing this again" .gitignore

# Push the edited repo. This will break other people's clones, if any.
git push origin master --force

有关详细信息,GitHub 上的删除敏感数据指南将为您提供帮助。

To completely remove a file from a git repository and its history, use these commands.

# Check out the remote repo
git clone git://host/path/repo.git
cd repo

# Clobber the file in your checkout
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch file-to-purge.txt' --prune empty --tag-name-filter cat -- --all

# Make sure you don't accidentally commit the file again
echo file-to-purge.txt >> .gitignore
git add .gitignore
git commit -m "Prevent accidentally committing this again" .gitignore

# Push the edited repo. This will break other people's clones, if any.
git push origin master --force

For more information, remove sensitive data guide at GitHub will help you.

场罚期间 2024-12-27 05:07:11

删除 git-hub 上的敏感数据的链接很有用。然而,我发现了一个非常易于使用的工具:Eric Raymond reposurgeon

这个工具允许我轻松导入我的存储库,列出有问题的提交,编辑它们(我单独这样做)并写出我的存储库的 git 快速导入流。我将该流导入到一个新的存储库中,并将其同步到位。

缺点是我的旧仓库完全死了——我改变了历史。根据文档,使用“git filter-branch”也是如此。

The link to removing sensitive data on git-hub is useful. However, I found a tool that was very straight-foward to use: Eric Raymond reposurgeon.

This tool allowed me to easily import my repo, list the commits with the issue, edit them (I did so individually) and write out a git fast-import stream of my repo. I imported that stream into a new repo and rsync'd it into place.

The downside is that my old repo is completely dead -- I changed history. That would be true of using "git filter-branch" as well, according to the docs.

无所谓啦 2024-12-27 05:07:11

如果您可以编辑服务器,则可以将分支头重置为前一个(HEAD^)。

  • 首先,获取您想要“恢复”的 HEAD^ 哈希值。
  • 转到(服务器中 git 裸存储库的目录)/refs/heads,更改为用户 git(或 git 服务的任何用户),运行“echo (hash) > (branch name)”进行重置。

就这样。顺便说一句,在执行上述操作之前,您无法更改拉取的存储库

If you can edit the server, you can reset branch head to the previous one (HEAD^).

  • first of all, get the HEAD^ hash you want to "revert" to.
  • go to (git bare repository's directory in server)/refs/heads, change to user git (or any the git serves), run "echo (hash) > (branch name)" to reset.

that's all. BTW, you cannot change the repo pulled before you did the above

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文