Git 合并提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4936778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:01:30  来源:igfitidea点击:

Git merge commits

gitgit-merge

提问by DiogoNeves

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).

我是 git 的新手(并且非常喜欢它!)。在新分支中进行开发时,我不断提交应用程序的各种开发“状态”。现在我必须检查它以供,但不希望所有内容都在不同的提交中(不同的评论和 ID)。

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

我怎样才能像第一次一样推送所有更改?

回答by stijn

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

允许您以交互方式选择最后 5 个提交中的哪一个加入一个;在我的头顶上,它会用这样的东西打开编辑器

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

这导致两个提交被留下:第一个合并了提交 1 - 4 的提交,以及单独留下的提交 5(最新的)

回答by Noufal Ibrahim

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.

我认为保留“微提交”是个好主意。您可以将功能之前的最后一次提交与当前 HEAD 进行比较,以查看可以发送以供审核的整个差异。