在 Git 上推送后如何合并提交?
我是git新手,我提交了一些更改,git告诉我需要先拉取,所以我拉取了,但是我的编辑器没有显示修改后的版本,所以我再次提交了冲突,我解决了冲突并再次提交。现在我有 3 个提交! (虽然我认为第一个不应该在那里)
问题是我每次提交后都会推送。那么有没有办法合并这些推送的提交呢?
您能提供一步一步的解释吗?我以前使用过 svn 和 cvs,但我对 git 很陌生
I am new to git, I committed some changes, git told me that I need to pull first, so I pulled but my editor didn't display the modified versions, so I committed again with conflicts, I resolved the conflicts and committed again. Now I have 3 commits! (although I think the first one should not be there)
The problem is that I pushed every time after each commit. So is there a way to merge those pushed commits?
Can you please provide a step by step explanation? I have used svn and cvs before but I am very new to git
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您描述的情况似乎不太可能,因为在冲突时尝试提交会导致以下错误:
如果您无法提交冲突,那么运行 git push 实际上不会推送更改。
您可以运行以下命令来查看实际发生的提交
The situation you described seems unlikely as trying to commit while in conflict results in the following error:
And if you couldn't commit the conflict then running git push wouldn't actually push the change.
You can run the following command to see what commits actually took place
如果我正确理解你的问题,这应该可以满足你的要求:
你可以使用 git rebase -i HEAD~3 将所有三个提交压缩在一起。这基本上将摆脱您的错误提交,并且最后一个提交中的内容将是最终内容。
当您运行该命令时,将弹出一个编辑器。将第二行和第三行中的
pick
替换为squash
。您将需要使用-f
标志再次推送。如果它们是您的最后三个提交,这将起作用。如果他们比这还落后的话。您将需要进一步变基,并且仅将
squash
放在要压缩的两个提交上。If I understand your question correctly, this should do what you want:
You can squash all three of those commits together with
git rebase -i HEAD~3
. This will basically get rid of your bad commits and the content in your last one will be the final content.When you run the command, an editor will pop up. Replace
pick
in the second and third line withsquash
. You will than need to push again with the-f
flag.This will work if they are your last three commits. If they are farther behind than that. You will need to rebase farther back and only put
squash
on the two commits you want to squash.