3

I created a local copy of a remote repository. Because of some old bad commit data causing trouble, I had to rewrite (filter-branch) the local repo history. So now I have a clone of a remote repo, except the commit hashes are all different.

Is there any way to have the local repo still work with remote for pulling future commits from it? It will never be pushing so that is not an issue. If I run git pull, it tries to pull it's entire original history, which is unwanted and just re-corrupts the local repo.

4

1 回答 1

2

如果您只关心拉动,那么可以。您可以做的是获取远程存储库。然后从与您最新的本地提交匹配的远程存储库中识别提交。然后将该远程提交合并到您的本地提交中,并带有-s ours标志(以设置ours策略)。这将产生一个将两个历史联系在一起的合并提交,同时仅使用本地历史中的树(因此,没有合并冲突)。

有了这个合并,您现在可以git pull安全地从远程存储库中,它只会尝试合并比您刚刚创建的虚拟合并更新的提交。

请注意,您仍然必须保留远程 repo 的整个历史记录,并且它可以作为虚拟合并的第二个父级访问。但它不会影响你当地的树。

于 2012-10-12T20:01:06.740 回答