【发布时间】:2015-03-03 08:21:16
【问题描述】:
我想将几个单一的提交推送到一个 git 远程仓库。我按照 Geoff 的回答在这里找到了这样做:
How can I pushing specific commit to a remote, and not the previous commits?
我要推送的提交不在前面,所以我必须先使用 rebase 重新排序提交,我使用这些说明来这样做:
http://gitready.com/advanced/2009/03/20/reorder-commits-with-rebase.html
基本上我已经完成了:
git clone
git commit
git commit
...
git pull
git rebase -i HEAD~3
git push origin <SHA>:master
我在执行此操作时出错。所以我开始深入研究这个问题。如果我在 rebase 后执行第二次 git pull,我发现我的日志中有重复的提交,例如:
git clone
git commit
git commit
...
git pull
git log --pretty=format:"%h - %an : %s" // log before rebasing
git rebase -i HEAD~3
git pull
git log --pretty=format:"%h - %an : %s" // log after rebasing
git pull
git log --pretty=format:"%h - %an : %s" // log after rebasing after pulling
所以我发布了这个问题:
git: Duplicate Commits After Local Rebase Followed by Pull
Roger 的回答让我想到了这个问题:为什么我在 rebase 和 pull 后看到重复的提交?
从上面看,变基前的日志如下:
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
注意原来的 2 次提交 2fc4fe7 和 b7a8656 有新的 SHA; 9777c56 和 a2d7d8b。我相信这是问题的开始。
现在,在我执行另一个 git pull 后,日志如下所示:
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
请注意,远程提交现已复制,并且远程提交的原始 SHA 2fc4fe7 和 b7a8656 已返回。
在 Roger 的回应中,他说这看起来像是其他人推送到 git 的错,并且他们正在重新定位他们已经推送的提交。但我相信在本地重新定位推送的提交是我的错。
这是因为我重新设置了已经推送到远程的提交吗?如果是这样,我应该怎么做才能避免这种情况?我需要重新提交我的提交,以便我可以推送一个提交。我应该使用分支系统来执行此操作吗?如果是这样,我将如何使用分支来解决这个问题?
【问题讨论】:
标签: git duplicates git-rebase git-pull