gpt4 book ai didi

git rebase 真正的旧提交

转载 作者:行者123 更新时间:2023-12-05 04:29:36 25 4
gpt4 key购买 nike

我正在尝试撤消已经推送到远程的非常旧的提交。我环顾四周,认为 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 应用它。然而,这引发了很多 merge 冲突(提交大约半年)。

我想撤消提交的原因是因为我不小心添加了一个带有凭据的文件,我不应该与其他协作者共享。
所以我唯一想撤消的是远程文件的“创建”。

git rebase 是最好的方法吗?
如果是这样,有没有办法不触发所有 merge 冲突(像以前一样 merge 它们)?
我宁愿不要意外地以错误的方式 merge 冲突。

此外,我尝试删除的提交不应与 future 的提交发生任何冲突。我尝试在不删除提交的情况下运行 git rebase,但 merge 冲突仍然 pop 。

最佳答案

感谢@ElpieKay!
git filter-repo 设法完成它的工作有关详细信息,请查看 here .
我首先尝试使用 BFG,但遇到了一些问题,所以我继续使用 git filter-repo

  1. 我确保我已经推送了所有本地提交。
  2. 我安装了git filter-repo
brew install git-filter-repo
  1. 我克隆了一个新的本地存储库 (git clone)。
    这一步是因为 git-filter-repo 提醒在新克隆的 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. 新克隆的 repo 将没有来源。添加它。
git remote add origin <your-repo-clone-url>
  1. 强制推送到原点
git push origin --force --all
  1. 最后要求在其他本地存储库中的所有其他旧分支上运行 rebase。
git checkout <the-branch-cut-from-the-old-main>
git rebase origin main

这应该可以解决问题!祝你好运!

关于git rebase 真正的旧提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72269881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com