git:在本地重新基址之后,在拉取之后重复提交

git:在本地重新基址之后,在拉取之后重复提交,git,duplicates,rebase,pull,Git,Duplicates,Rebase,Pull,我有一个本地git存储库,并运行以下操作: git.exe pull -v --no-rebase --progress "origin" // pull 1 (make a few local commits) git.exe pull -v --no-rebase --progress "origin" // pull 2 git log --pretty=format:"%h - %an : %s" // log 1 git rebase -i HEAD~4 (move l

我有一个本地git存储库,并运行以下操作:

git.exe pull -v --no-rebase --progress "origin" // pull 1
(make a few local commits)
git.exe pull -v --no-rebase --progress "origin" // pull 2
git log --pretty=format:"%h - %an : %s"         // log 1
git rebase -i HEAD~4
(move local commit 1 down 2 positions)
git log --pretty=format:"%h - %an : %s"         // log 2
git.exe pull -v --no-rebase --progress "origin" // pull 3
git log --pretty=format:"%h - %an : %s"         // log 3
完成此操作后,我在pull 1中检索到的对远程存储库的所有提交现在都复制到日志中

日志1如下所示:

84e4015 - Me : Local Commit 3
0dbe86a - Me : Local Commit 2
d57ba2a - Me : Merge branch 'master' of remote repository
a86ea35 - Me : Local Commit 1 before reordering
2fc4fe7 - Remote User 2 : Remote Commit 2
b7a8656 - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
e8e1a85 - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
2fc4fe7 - Remote User 2 : Remote Commit 2 // duplicate 2
b7a8656 - Remote User 1 : Remote Commit 1 // duplicate 1
8ce80fc - Me : Merge branch 'master' of remote repository
日志2如下所示:

84e4015 - Me : Local Commit 3
0dbe86a - Me : Local Commit 2
d57ba2a - Me : Merge branch 'master' of remote repository
a86ea35 - Me : Local Commit 1 before reordering
2fc4fe7 - Remote User 2 : Remote Commit 2
b7a8656 - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
e8e1a85 - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
2fc4fe7 - Remote User 2 : Remote Commit 2 // duplicate 2
b7a8656 - Remote User 1 : Remote Commit 1 // duplicate 1
8ce80fc - Me : Merge branch 'master' of remote repository
日志3如下所示:

84e4015 - Me : Local Commit 3
0dbe86a - Me : Local Commit 2
d57ba2a - Me : Merge branch 'master' of remote repository
a86ea35 - Me : Local Commit 1 before reordering
2fc4fe7 - Remote User 2 : Remote Commit 2
b7a8656 - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
8ce80fc - Me : Merge branch 'master' of remote repository
e8e1a85 - Me : Merge branch 'master' of remote repository
cf1ff7b - Me : Local Commit 3
cd14463 - Me : Local Commit 2
b9d44fb - Me : Local Commit 1 after reordering
9777c56 - Remote User 2 : Remote Commit 2
a2d7d8b - Remote User 1 : Remote Commit 1
2fc4fe7 - Remote User 2 : Remote Commit 2 // duplicate 2
b7a8656 - Remote User 1 : Remote Commit 1 // duplicate 1
8ce80fc - Me : Merge branch 'master' of remote repository
我做错了什么?如何预防?我怎么修理


请注意,我从未推送到远程存储库,只是从中提取并进行本地提交。还要注意的是,这个问题有很多标题类似的帖子,但它们都有点不同,这里的答案似乎不适用。

不是你,而是远程用户。看起来他们已经重新确定了您已经基于的提交的基础,然后将其推回到原点。不太善于交际


线索是远程用户的提交引用从log1更改为log2——他们重新设置并推进了工作。但你的工作是基于他们的预重定基承诺。因此,您的本地回购包含这两个提交(2fc4fe7、b7a8656),它们的rebase已经从回购和原始中删除了这两个提交(可能它们是通过
--force
推动的)。因此,当您从源位置拉取时,这些本地提交似乎会重新生成,以确保保存您的提交历史记录,并且远程用户的重定基准提交(9777c56,a2d7d8b)也会合并。因此出现了重复项。

问题在于git pull。我应该使用:

git pull --rebase
这将重新调整我的本地提交,使它们位于顶部,即比远程回购中的提交更新。因此,当我将我的提交重新定基以重新排序一个时,我并没有将推送到远程回购的提交重新定基。通过对推送到远程回购的提交进行重定,我复制了它们并为它们分配了一个新的SHA,当我进行第二次git拉取时,它重新拉取了原始的SHA/提交,从而复制了它们

有关更多详细信息,请参见此处:


谢谢,罗杰。相关问题,若我有3次提交,提交3次(最新)、提交2次(中间)和提交1次(最早)。我按了3键。然后我重新设置了提交1的基础,使其成为最新的,然后推送提交1。我会给其他用户造成同样的失败吗?事实上,罗杰,看起来我的本地rebase在日志2中为远程用户的提交提供了一个新的SHA、9777c56和a2d7d8b。这不应该发生,是吗?当我拉动它时,它重新创建了最初在日志1、2fc4fe7和b7a8656中看到的原始SHA。你确定这不是我的错吗?如果是我的错,我做错了什么?根据你最初的帖子,你没有推动另一次回购,因此,在你的本地回购中发生的任何事情都不会对世界其他地区产生影响。您可以随意处理在本地进行的(新)提交,但一旦推回到原点,或从原点拉取新提交,就不能重新设置这些提交的基础。很好的解释。事实上,再看一遍,这根本没有意义。在日志中获取重复项通常是远程用户重定您所依赖的提交的标志,但在这种情况下,远程用户的提交会在不拉动的情况下更改。你能准确地记得你在互动式再基地做了什么吗?日志似乎与行动不符。例如,将log1与操作列表进行比较,pull2之间如何发生提交0d和84以创建合并提交d5和正在生成的log1?您可以将
git pull--rebase origin[您的本地分支]
想象为在您处理本地分支时,如果其他人向origin作出了提交,您希望提交历史记录看起来像是您在他们之后完成了您的工作。无论提交的顺序(重基位)如何,您都必须在某个点进行合并。git pull进行合并,因为在封面下是git获取,然后是git合并。因此,
git pull--rebase
是您需要的合并,它将本地提交放在任何远程提交之后。以后别忘了推回原点。可能的副本