git 没有合并分支的合并提交历史源树

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

merge without merged branch commits history sourcetree

gitmergecommitatlassian-sourcetree

提问by Asaf Maoz

enter image description here

在此处输入图片说明

I need to merge a feature branch into my master branch in SourceTree.

我需要将一个功能分支合并到我在 SourceTree 中的主分支中。

Every time I merge the feature branch, I see in the master branch commit history all the feature branch commits history.

每次合并功能分支时,我都会在主分支提交历史记录中看到所有功能分支提交历史记录。

I want to merge the feature branch into my master branch and in the master branch to see only one commit added, the 'merged with branchName' commit, that lists the files changed.

我想将功能分支合并到我的主分支和主分支中,以查看仅添加了一个提交,即“与分支名称合并”提交,其中列出了已更改的文件。

I had that option in smart git, can it be done in SourceTree? How?

我在 smart git 中有这个选项,可以在 SourceTree 中完成吗?如何?

  • A: Commit done in the master branch
  • B,C: Commits done on test_branch branch, shown in the master commits history (these are the ones I want to remove from my master history)
  • D: The merge commit (I want to keep this one)
  • A: 在主分支中完成提交
  • B、C:在 test_branch 分支上完成的提交,显示在主提交历史中(这些是我想从主历史中删除的那些)
  • D:合并提交(我想保留这个)

采纳答案by VonC

That means the merge is a fast-forwardone: it simply moves master HEAD to feature branch HEAD.

这意味着合并是快进的:它只是将主 HEAD 移动到功能分支 HEAD。

The blog post "Merge or Rebase?" (August 2012) mentions:

博文“ Merge or Rebase?”(2012 年 8 月)提到:

You can turn fast-forward merges off in SourceTree so that a merge commit is always created if you want - check the 'Create a commit' option in the Mergedialog or set it globally in Preferences > Git.]

您可以在 SourceTree 中关闭快进合并,以便根据需要始终创建合并提交 - 检查对话框中的“ Create a commit”选项Merge或在Preferences > Git.]

Note: if you are using git-flowwith SourceTree, then the merge would alwaysbe a fast-forward one if fast-forward is possible: see this thread.

注意:如果您git-flow与 SourceTree一起使用,那么如果可以进行快进,则合并将始终是快进的:请参阅此线程

The screenshot added by the OP reveals a non-fast-forward merge, with:

OP 添加的屏幕截图显示了非快进合并,其中:

  • a merge commit in master history
  • commits done in feature branch
  • 主历史中的合并提交
  • 在功能分支中完成的提交

So A-Dis in master, while B-Cremain in featurebranch: you don't have to "remove" B-Cfrom masterhistory.
The current branch(master) only has A-D. The featurecommits are only visible as a context, to explain where the merge commit Dis coming from.

所以A-Dmaster,而B-C留在feature分行:你不必为“删除”B-Cmaster历史。
当前分支master)只A-D。该feature提交才可见的背景下,说明在合并提交D的来源。



Note: this (the merge commit) is represented in GitHub with bothparents, meaning including the latest commit of the the merged branch: it is a "feature" from GitHub, not an accurate representation of masterhistory.

注意:这个(合并提交)在 GitHub 中与父母双方一起表示,这意味着包括合并分支的最新提交:它是来自 GitHub 的“功能”,而不是master历史的准确表示。

See for instance the commits in the masterbranch of the Git repo itself: each merge commit is followed by one commit from the merged branch.

例如,查看Git 存储库本身master分支中的提交:每个合并提交后跟来自合并分支的一个提交。

In the case of the second screenshot, GitHub displays the commits from the merged branch, but those commits aren't part of the history of master (a git log masterwouldn't list them).
It is a feature from GitHub, not an exact view of the masterlog.

在第二个屏幕截图的情况下,GitHub 显示来自合并分支的提交,但这些提交不是 master 历史记录的一部分(agit log master不会列出它们)。
这是 GitHub 的一项功能,而不是master日志的准确视图。

Note bis: those merged commits are displayed by GitHub according to their date.
If they are recent, you see them right under the merge commit, if they are older, you see them further down in the commit history list of the masterbranch.

注意之二:GitHub 会根据日期显示这些合并的提交。
如果它们是最近的,您可以在合并提交的正下方看到它们,如果它们较旧,您可以在master分支的提交历史列表中进一步看到它们。



The OP Asaf Maozadds in the comments:

OP阿萨夫毛兹补充说在评论

when I used smart git I had an option to merge branches and see only one commit in my master branch (similar to those in your link) - the merged commit,

当我使用 smart git 时,我可以选择合并分支,并且在我的主分支中只看到一个提交(类似于您链接中的那些)——合并的提交,

This doesn't seem to be supported yet in ST (see the ST forum).
Even displaying the nameof the current branch isn't there yet (SRCTREE-1925)

ST 似乎尚不支持此功能(请参阅ST 论坛)。
甚至还没有显示当前分支的名称( SRCTREE-1925)

I didn't change anything in my github account, so it must be in the ST. maybe this option does not exist in ST

我在我的 github 帐户中没有更改任何内容,所以它必须在 ST 中。也许这个选项在 ST 中不存在

Yes: each tool chose its graphical display of a git log.

是的:每个工具都选择了它的图形显示git log.