git Intellij - 如何仅压缩本地分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35018704/
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 11:43:38  来源:igfitidea点击:

Intellij - How to squash local branch only

gitintellij-ideaintellij-14git-squash

提问by NikZ

When using Git inside of Intellij, how do I squash all of my commits for a local branch? What settings do I use in the rebase branch window?

在 Intellij 中使用 Git 时,如何压缩本地分支的所有提交?我在 rebase 分支窗口中使用哪些设置?

I've tried setting the Onto to local/master and From to my branch, but then it goes and tries to merge master changes into my branch for each commit I did, even tho I typically rebase my branch onto master every morning...so there SHOULD be no conflicts. Yet it almost always finds conflicts and causes merge issues. I ONLY want to squash the branch commits and messages so when I push to Github it only sees one.

我已经尝试将 Onto 设置为 local/master 并将 From 设置为我的分支,但随后它会尝试将我所做的每次提交的主更改合并到我的分支中,即使我通常每天早上将我的分支重新设置为 master ......所以应该没有冲突。然而,它几乎总是会发现冲突并导致合并问题。我只想压缩分支提交和消息,所以当我推送到 Github 时它只能看到一个。

enter image description here

在此处输入图片说明

回答by Alim ?zdemir

It might be a little uncomfortable but you can use the git notation of HEAD~ so in the "Onto" field you'd write the amount of commits you want to include like:

这可能有点不舒服,但您可以使用 HEAD~ 的 git 符号,因此在“Onto”字段中,您可以写下您想要包含的提交数量,例如:

In this example I have 4 (the last 4) commits I want to combine into 1.

在这个例子中,我有 4 个(最后 4 个)提交,我想合并为 1 个。

rebase interactive dialogue

In the opening dialog the entries are listed in order, so you need to squash all after the first one with the drop box. (I made the first a reword but that's not needed as there will be a message-change dialog for the squashing anyway, so it can be left on 'pick')

rebase 互动对话

在打开的对话框中,条目按顺序列出,因此您需要使用下拉框压缩第一个之后的所有条目。(我对第一个进行了改写,但这不是必需的,因为无论如何都会有一个用于挤压的消息更改对话框,因此可以将其保留在“选择”上)

squashing

then just a new message for the combined commits and you're done.

压扁

然后只是合并提交的新消息,您就完成了。

commit message

提交消息

回答by David

If you want something like "git merge -squash" means merge a branch to another branch (possibly "master") with one commit contains all of the changes, you can use "Merge Changes..." option in Intellij. Just double press shift and type "Merge Changes". In the opened dialog select what branch you want to merge and then select "Squash commit" option.

如果你想要像“git merge -squash”这样的东西意味着将一个分支合并到另一个分支(可能是“master”),一个提交包含所有更改,你可以使用 Intellij 中的“合并更改...”选项。只需双击 shift 并输入“合并更改”。在打开的对话框中选择要合并的分支,然后选择“Squash commit”选项。

enter image description here

在此处输入图片说明