本文介绍了如何将git-replace推送到远程仓库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用"git replace"来替换分支(没有共同祖先)22b2b25来进行master提交.我希望此更改是永久的.我对以前的历史不感兴趣.在下面的输出中,前五个提交来自原始master分支,下两个提交来自另一个分支.

I have used "git replace" to substitute a branch (with no common ancestor) 22b2b25 for a commit in master. I want this change to be permanent. I'm not interested in the previous history. In the output below the top five commits are from the original master branch and the bottom 2 come from a different branch.

当我将其推送到新的存储库时,git-replace丢失了,旧的历史记录又出现了.有没有办法使这项更改永久生效?

When I pushed this to a new repository the git-replace was lost and the old history reappeared. Is there a way to make this change permanent?

分支母版看起来像原始回购中的以下内容.我想在远程仓库和后续克隆中看到这一点.

branch master looks like the below in the original repo. I want to see this in the remote repo and subsequent clones.

[mike@localhost canal_site]$ git log --oneline --decorate
cdf0ae3 (HEAD, origin/master, master) MM: sqlencode course name for ad-hoc courses
2b57df5 MM: fixes for changes so far
7916eaf MM: ad hoc - more refactoring
1e00d22 MM: reformatted code
e36cee1 factored out equal ops
22b2b25 (origin/prod20140313, prod20140313) initial load from production 9-June-2015
08379cd initial inclusion of production files from 9-June-2015

推荐答案

git replace 仅凭光是不够的:替换一次提交是不够的.

git replace alone isn't enough: replacing one commit isn't enough.

下一个提交现在必须将替换的提交作为父引用.

The next commit must now reference the replaced commit as a parent.

如"从git中删除一大堆提交":

git replace bbb aaa
git filter-branch -- --all

然后,您需要强制执行推送(git push --force),以便使用分支的新历史记录覆盖远程仓库.或者,您只需推送到一个新的空裸仓库即可.

Then you would need to force push (git push --force) in order to override the remote repo with the new history of the branch. Or you van just push to a new empty bare repo.

更新(灵感来自 Stephen 的评论)

Update (inspired from Stephen's comment)

正如我在2019年10月在"可能破坏/重写历史记录的Git命令"中所述,git filter-分支或BFG已过时.
git filter-repo 更加易于使用和高效.

As I noted in Oct. 2019 in "Git commands that could break/rewrite the history", git filter-branch or BFG are obsolete.
git filter-repo is easier to use and more efficient.

这篇关于如何将git-replace推送到远程仓库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 06:17