git:本地Rebase之后重复提交 [英] git: Duplicate Commits After Local Rebase Followed by Pull
问题描述
我有一个本地git存储库,我运行以下命令:
I have a local git repository and I run the following:
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
完成之后,所有提交给我在拉1中检索到的远程存储库的提交现在都重复在日志中。
After doing this all commits to the remote repository that I retrieved in pull 1 are now duplicated in the log.
日志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
日志2如下所示:
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
而日志3看起来像这个:
And log 3 looks like this:
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
我做错了什么?如何防止?如何修复?
What have I done wrong? How do I prevent? How do I fix?
请注意,我从未推送到远程存储库,仅从其中提取并进行了本地提交。还要注意的是,这个问题有很多类似的标题,但是它们都有一些不同,这里的答案似乎不适用于这里。
Note that I've never pushed to the remote repository, only pulled from it and made local commits. Also note that there are a lot of similarly titled threads to this question but all of them are a little different and the answers there don't seem to apply here.
推荐答案
问题在于git pull。我应该使用:
The problem is with git pull. I should have used:
git pull --rebase
这会使我的本地提交更新,以便它们与远程回收中的提交相比更上一层楼,即更新。所以当我修改我的命令来重新排序一个,我不是重新提交被推送到远程回购的提交。通过重新推送已经被推送到远程回购的承诺,我正在复制它们并为其分配一个新的SHA,当我进行第二个git pull时,它重新拉出了原始的SHA /提交,因此重复。
This rebases my local commits so that they are on top, i.e. more recent, than the commits in the remote repo. So when I rebase my commits to reorder one, I'm not rebasing commits that have been pushed to the remote repo. By rebasing commits that had been pushed to the remote repo I was copying them and assigning them a new SHA, and when I did the second git pull it re-pulled the original SHAs/commits, hence the duplicates.
请参阅这里了解更多详情:
See here for more details:
git: Pushing Single Commits, Reordering with rebase, Duplicate Commits
这篇关于git:本地Rebase之后重复提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!