简体   繁体   English

Git-不与--squash合并

[英]Git --no-merged with --squash

I prefer to merge my feature branches with --squash as it lets me track when features were added, and it is usually complete features that I need to bisect on. 我更喜欢将功能分支与--squash合并,因为它可以让我跟踪添加功能的时间,通常它是需要bisect完整功能。 I find that this gives a very nice representation of the state of the stable branch over time. 我发现随着时间的推移,这可以很好地表示稳定分支的状态。

However, when using --squash branches merged appear under --no-merged instead of under --merged . 但是,当使用--squash分支时,合并的分支将显示在--no-merged而不是在--merged下。 This makes it sometimes difficult to keep track of the state of each branch (ie when it is finished). 这有时使难以跟踪每个分支的状态(即完成时)。 I do not want to delete the 'finished' branches as it has happened that I have had to check them out to bisect further and also other reasons (sometimes a problem requires multiple paths of attack until it is solved, and I have found it valuable to have that documented). 我不想删除“完成的”分支,因为碰巧我不得不将它们检出以进一步平分,还有其他原因(有时问题需要多条攻击路径才能解决,而我发现它很有价值记录下来)。

It there any way to either: 可以通过以下任何一种方式:

  • Have --merged and --no-merged recognise that squashed branches have in fact been merged. --merged--no-merged承认压扁分行实际上已经被合并。

or 要么

  • Archive merged (squashed) branches in the sense that they will not appear in either listing, but are still available if I need them. 归档合并(压缩)分支在某种意义上说它们不会出现在任何一个列表中,但是如果我需要它们仍然可用。

I actually do prefer the second solution if possible. 实际上,如果可能的话,我确实更喜欢第二种解决方案。 There are quite a few non-current branches accumulating and hiding them will make it easier to search the list for the current branch that I am looking for. 有很多非当前分支的积累和隐藏它们将使在列表中查找我正在寻找的当前分支变得更加容易。

Branches are merged, if—and only if—another branch has them as a direct or indirect parent (ie when following the parents of the commits, you will at some time reach that branch). 当且仅当另一个分支将它们作为直接或间接父级合并时,分支才会合并(即,当遵循提交的父级时,您有时会到达该分支)。 There are no exceptions from this. 这也不例外。

When you squash changes, you are creating a new commit object that contains all the changes from that one branch at once. 压缩更改时,将创建一个新的提交对象,该对象一次包含该分支中的所有更改。 So you have a “new branch” for that one commit, and the old branch stays around to keep the original commits available. 因此,您有一个用于该提交的“新分支”,而旧分支一直存在以保持原始提交可用。 Now when you merge, you merge that one commit, so only that one's branch gets merged. 现在,当您合并时,将合并一个提交,因此仅合并一个分支。

So no, when you squash the changes, the original branch that still contains the individual commits won't be recognized as merged, simply because it isn't merged. 因此,不,当您压缩更改时,仅包含未提交的原始分支将不会被视为合并,这仅仅是因为未合并。 There is also no way to change this behavior, or to “archive” a branch. 也没有办法更改此行为或“存档”分支。 The only thing you could do is to create a tag for the branch instead, as a marker, so you can then delete the branch itself. 您唯一可以做的就是改为为分支创建一个标记,作为标记,这样您就可以删除分支本身。

However, the proper way is to just merge the full branch. 但是,正确的方法是仅合并完整分支。 Especially if you are saying that you want the original branch “still available if [you] need them”. 特别是如果您要说原始分支“如果需要则仍然可用”。 If you want that, then you should just keep the original branch inside the history, so it's a real part of the history. 如果你想,那么你应该只保留历史里面原来的分支,所以它是历史的真正的一部分。

If you worry about the readability of the history, you should consider making non-fast-forward merges all the time, so the branches you merge in always appear separately on the side. 如果您担心历史记录的可读性,则应考虑始终进行非快进合并,因此合并的分支始终总是单独出现在侧面。

You could just merge normally (without squashing) and use the --first-parent option to your git commands. 您可以正常合并(不压缩)并在git命令中使用--first-parent选项。 For example 例如

git log --first-parent

to "simplify" history. 以“简化”历史。 This will simplify the feature branch to a merge commit entry only and you will not see the commits on the merged branch. 这会将要素分支简化为仅合并提交条目,并且您将不会在合并分支上看到提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM