开发者

How do I merge commits after I have already pushed on Git?

I am new to git, I committed some changes, git told me that I need to pu开发者_运维百科ll 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


The situation you described seems unlikely as trying to commit while in conflict results in the following error:

fatal: 'commit' is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as
appropriate to mark resolution and make a commit, or use 'git commit -a'.

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 log --patch --color


If I'm understanding your question corrrectly, 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜