在 IntelliJ IDE 中将分支与 Git 合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43721726/
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
Merging branches with Git in IntelliJ IDE
提问by Devil's Advocate
I know there are dozens of questions on this, but I'm having trouble. First off, I'm using Webstorm (IntelliJ) not the command line. Second, this seems to vary by perspective.
我知道有很多关于此的问题,但我遇到了麻烦。首先,我使用的是 Webstorm (IntelliJ) 而不是命令行。其次,这似乎因观点而异。
I have my master branch, obviously. I created a new branch called "InlineEditing". I've been working in this branch for a couple days. There have been no changes to the master branch. I now want to move all the changes in the current branch back to the master and resume working from there.
显然,我有我的主分支。我创建了一个名为“InlineEditing”的新分支。我已经在这个分支工作了几天。master 分支没有任何变化。我现在想将当前分支中的所有更改移回 master 并从那里继续工作。
In Webstorm, with InlineEditing as the current branch, I tried merging using the following method but it doesn't seem to do anything. Ie, when I then checkout the master branch, it's the old code.
在 Webstorm 中,以 InlineEditing 作为当前分支,我尝试使用以下方法进行合并,但似乎没有任何作用。即,当我检出 master 分支时,它是旧代码。
So my question is, what is the proper way to "merge" my current branch back to the master?
所以我的问题是,将我当前的分支“合并”回主分支的正确方法是什么?
回答by dgraf
You normally have two merge use cases.
您通常有两个合并用例。
- First use caseis as you have already described: there are no changes in the master branch. In this case the merge is pretty easy, see the steps on the picture below.
- 第一个用例正如您已经描述的那样:主分支中没有变化。在这种情况下,合并非常简单,请参阅下图的步骤。
- Second use caseis a bit complicated: there are some changes in the master branch. You want first update the master and the InlineEdit and then merge InlineEdit into master. See the steps on the picture below.
- 第二个用例有点复杂:主分支中有一些变化。您要先更新母版和 InlineEdit,然后将 InlineEdit 合并到母版中。请参阅下图中的步骤。
回答by Tim Biegeleisen
The standard workflow you are following goes something like this:
您遵循的标准工作流程如下所示:
git checkout InlineEditing
# work work work
git commit -m 'finished my work'
# now switch to master and merge the feature branch into it
git checkout master
git merge InlineEditing
# resolve any merge conflicts; IntelliJ is great for this step
It might be slightly counterintuitive that you have to switch to master
in order to merge another branch into it. Instead, you might have expected to be able to merge InlineEditing
into master
from the former branch. This is just how Git works.
您必须切换到master
以将另一个分支合并到其中可能有点违反直觉。相反,你可能期望能够合并InlineEditing
到master
从以前的支路。这就是 Git 的工作原理。
With regard to your original question about IntelliJ, I think there is nothing wrong with using a GUI tool for Git, provided that you know what you are doing. I tend to do most Git operations from the command line, because I am experienced doing this and the command line is powerful. But there are many cases where I use tools like IntelliJ. For example, resolving merge conflicts is much easier in IntelliJ than the command line. Also, visualizing the history of a branch can be easier using a GUI tool.
关于您最初关于 IntelliJ 的问题,我认为使用 Git 的 GUI 工具没有任何问题,前提是您知道自己在做什么。我倾向于从命令行执行大多数 Git 操作,因为我有这样做的经验并且命令行功能强大。但是在很多情况下我会使用 IntelliJ 之类的工具。例如,在 IntelliJ 中解决合并冲突比在命令行中容易得多。此外,使用 GUI 工具可以更轻松地可视化分支的历史记录。