git rebase真的很老

发布于 2025-01-29 11:32:30 字数 660 浏览 4 评论 0原文

我正在尝试撤消一项非常古老的提交,该提交已经被推到遥控器上。 我环顾四周,以为git rebase可能是最好的解决方案。 因此,我运行了代码:

git rebase -i <commit-id>

然后编辑:

pick <commit-id> <commit-title>
drop <commit-id> <commit-title>   <- the commit I want to delete
pick <commit-id> <commit-title>

然后尝试使用:WQ应用此代码。但是,这引发了很多合并冲突(该提交大约是半年的)。

我要撤消该提交的原因是因为我不小心添加了一个带有凭据的文件,我不应该与其他合作者分享。
因此,我唯一要撤消的是遥控器上文件的“创建”。

git rebase最好的方法吗?
如果是这样 我宁愿不要以错误的方式偶然地合并冲突。

我试图删除的提交也不应与未来的提交造成任何冲突。我尝试运行git rebase而不会丢弃提交,但合并冲突仍然弹出。

I am trying to undo a really old commit that has already been pushed to the remote.
I looked around and thought that git rebase was probably the best solution.
so I ran the code:

git rebase -i <commit-id>

then edited:

pick <commit-id> <commit-title>
drop <commit-id> <commit-title>   <- the commit I want to delete
pick <commit-id> <commit-title>

Then tried applying this with :wq. This however triggered a LOT of merge conflicts (the commit is about half a year old).

The reason I want to undo the commit is because I accidentally added a file with credentials on it that I should not share with other collaborators.
So the only thing I want to undo is the "creation" of the file on the remote.

Is git rebase the best approach?
if so is there a way not to trigger all the merge conflicts (merge them just like before)?
I would rather not accidentally merge a conflict in the wrong way.

Also the commit I am trying to delete should not cause any conflicts with future commits. I tried running git rebase without dropping the commit but the merge conflicts still popped up.

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

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

发布评论

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

评论(1

幸福不弃 2025-02-05 11:32:30

感谢@elpiekay!
git filter-repo设法完成了工作
有关完整详细信息,请查看在这里
我首先尝试使用bfg,但是我遇到了一些问题,因此我转到git filter-repo

  1. 我确保我已经推动了所有当地提交。
  2. 我安装了git filter-repo
brew install git-filter-repo
  1. 我克隆了一个新的本地存储库(git clone)。
    此步骤是因为git-filter-repo警报以在刚克隆的仓库中运行该命令。
  2. 删除凭据文件并将其添加到.gitignore
    如果还没有,请确保在其他地方保存凭据。
git filter-repo --invert-paths --path PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA
echo "YOUR-FILE-WITH-SENSITIVE-DATA" >> .gitignore
git add .gitignore
git commit -m "deleted file <file-name> and added to .gitignore"
  1. 新克隆的仓库将没有起源。添加。
git remote add origin <your-repo-clone-url>
  1. Force推到原点
git push origin --force --all
  1. 最终要求在其他本地存储库中的所有其他旧分支上进行重新构想。
git checkout <the-branch-cut-from-the-old-main>
git rebase origin main

那应该解决问题!祝你好运!

Thanks to @ElpieKay!
git filter-repo managed to do its job
For full details look here.
I first tried to use BFG, but I had some issues so I moved on to git filter-repo.

  1. I made sure I had pushed all local commits.
  2. I installed git filter-repo
brew install git-filter-repo
  1. I cloned a new local repository (git clone).
    This step was because git-filter-repo alerted to run the command in a freshly cloned repo.
  2. Delete the credentials file and add it to .gitignore.
    Make sure to save the credentials elsewhere if you haven't already.
git filter-repo --invert-paths --path PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA
echo "YOUR-FILE-WITH-SENSITIVE-DATA" >> .gitignore
git add .gitignore
git commit -m "deleted file <file-name> and added to .gitignore"
  1. newly cloned repo will not have an origin. Add it.
git remote add origin <your-repo-clone-url>
  1. force push to origin
git push origin --force --all
  1. Lastly ask to run a rebase on all other old branches in other local repositories.
git checkout <the-branch-cut-from-the-old-main>
git rebase origin main

And that should do the trick! Good Luck!

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