Git merge commits [duplicate]

这一生的挚爱 提交于 2019-12-03 02:12:50

问题


I'm new to git (and enjoying it a lot!). While developing in a new branch, I kept committing the various development 'states' of my application. Now I have to check it in for review but didn't want everything to go in different commits (different comments and ids).

How can I do a push of all changes as if it was the first time?


回答1:


git rebase -i HEAD~5

allows you to interactively select which of the 5 last commits to join into one; off the top of my head it opens the editor with something like this

pick xxxx commit1
pick xxxx commit2
pick xxxx commit3
pick xxxx commit4
pick xxxx commit5

you change this into

pick xxxx commit1
squash xxxx commit2
squash xxxx commit3
squash xxxx commit4
pick xxxx commit5

which results in two commits being left: first one that has combined commits 1 - 4, and commit 5 (the newest one) which is left alone




回答2:


I think it's a good idea to keep your "micro commits". You can do a diff from the last commit before your feature to the current HEAD to see the entire diff which you can send for review.



来源:https://stackoverflow.com/questions/4936778/git-merge-commits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!