简体   繁体   English

我怎么知道分支是否已经在SVN / Mercurial / Git中合并?

[英]How do I know if a branch has already been merged in SVN/Mercurial/Git?

Is there any way of easily deciphering (ie at a glance) whether or not a branch has already previously been merged with the another branch or the trunk? 是否有任何方法可以轻松解密(即一目了然)分支是否先前已与另一个分支或主干合并? The nearest I've been able to figure out is by looking at the commit notes and displaying the merged commit notes. 我能够弄清楚的最近的是查看提交注释并显示合并的提交注释。 The disadvantage with this seems to be that unless you know which branch the commit notes are imported from, there's no way to decipher which branches have already been merged or not. 这样做的缺点似乎是,除非您知道从哪个分支导入提交注释,否则无法解密哪些分支已经合并。

Edit : Is Mercurial or Git any more intuitive than SVN for this? 编辑 :Mercurial或Git是否比SVN更直观?

Is Mercurial or Git any more intuitive than SVN for this? Mercurial或Git是否比SVN更直观?

Yes, very much so: 是的,非常如此:

sjl at ecgtheow in ~/src/hg-review on webui at tip
[10] $ hg glog
@  changeset: 113:c5debb475273 Steve Losh tip webui
|  summary:   Add file folding.
|
o  changeset: 112:a3ad66636756 Steve Losh  webui
|  summary:   Show skipped-line comments.
|
o  changeset: 111:2e65351af702 Steve Losh  webui
|  summary:   Rough cut of line-level comments.
|
| o  changeset: 110:b599ca22418d Steve Losh  
|/|  summary:   Merge the bug fix.
| |
o |  changeset: 109:e2ddb8631463 Steve Losh  webui
| |  summary:   Fix the event not defined bug.
| |
| o  changeset: 108:001f5ecfd9bc Steve Losh  
|/|  summary:   Merge the webui skipped line counts -- too important to leave in the
| |             branch.
| |
o |  changeset: 107:1cc8e18b1b43 Steve Losh  webui
| |  summary:   Add skipped line counts to diffs.
| |

EDIT: Git has a git log --graph option that's pretty much the same as Mercurial's, except without the helpful you-are-here @ character. 编辑: Git有一个git log --graph选项与Mercurial的几乎相同,除了没有帮助你在这里@字符。

On git, you can use git log to ask if one branch includes another: 在git上,你可以使用git log来询问一个分支是否包含另一个分支:

git log topic ^master # list all commits in branch 'topic', but not in 'master'

If nothing is returned, topic has been merged. 如果未返回任何内容,则topic已合并。

Type: 类型:

svn help mergeinfo

And you get: 你得到:

mergeinfo: Display merge-related information.
usage: mergeinfo SOURCE[@REV] [TARGET[@REV]]

  Display information related to merges (or potential merges) between
  SOURCE and TARGET (default: '.').  If the --show-revs option
  is not provided, display revisions which have been merged from
  SOURCE to TARGET; otherwise, display the type of information
  specified by the --show-revs option.

Valid options:
  -r [--revision] ARG      : ARG (some commands also take ARG1:ARG2 range)
                             A revision argument can be one of:
                                NUMBER       revision number
                                '{' DATE '}' revision at start of the date
                                'HEAD'       latest in repository
                                'BASE'       base rev of item's working copy
                                'COMMITTED'  last commit at or before BASE
                                'PREV'       revision just before COMMITTED
  --show-revs ARG          : specify which collection of revisions to display
                             ('merged', 'eligible')

In git, you can use --contains to list branches that contain other branches: 在git中,您可以使用--contains列出包含其他分支的分支:

git branch -a --contains feature

will show all branches (with -a , that includes remote branches) that have merged the given feature. 将显示已合并给定功能的所有分支(使用-a ,包括远程分支)。

git show-branch will show lots of details of the relationships between branches. git show-branch将显示git show-branch之间关系的大量细节。 It takes a bit of time to learn to read it effectively, but it's very valuable and will show you a lot in a small amount of space. 学习有效阅读它需要一些时间,但它非常有价值,并会在很小的空间内向您展示。

If you have a version of the server which is at least 1.5 as mentioned by chotchki, and your repository has been created with such a version or upgraded, the property svn:mergeinfo is added to any directory in which a merge has occurred. 如果chotchki提到的服务器版本至少为1.5,并且您的存储库已使用此类版本创建或升级,则属性svn:mergeinfo将添加到发生合并的任何目录中。

Let's say you have reintegrated two branches in the trunk, you can check with (replace with your URL): 假设您已经在主干中重新集成了两个分支,您可以检查(替换为您的URL):

svn propget svn:mergeinfo svn://localhost/Test/trunk

which branches have been merged and which revisions they modified. 合并了哪些分支以及修改了哪些修订。 Example of output: 输出示例:

/branches/dev/1:35-36
/branches/dev/2:38-39

With a GUI client like TortoiseSVN, check at the graph or look at the properties of the target directory in the repo-browser. 使用像TortoiseSVN这样的GUI客户端,检查图表或查看repo-browser中目标目录的属性。

In Git , you can use git branch --merged <commit> , which lists all branches which are reachable from given commit ( <commit> defaults to HEAD, which means that git branch --merged would list all branches merged into current commit). Git中 ,您可以使用git branch --merged <commit> ,它列出了从给定提交可以访问的所有分支( <commit>默认为HEAD,这意味着git branch --merged将列出合并到当前提交的所有分支) 。

Or you can use git show-branch branch1 branch2 or git log --graph --oneline branch1 branch2 to see history graphically (or use some graphical history browser like gitk, QGit, Giggle, GitX, etc.). 或者您可以使用git show-branch branch1 branch2git log --graph --oneline branch1 branch2以图形方式查看历史记录(或使用一些图形历史记录浏览器,如gitk,QGit,Giggle,GitX等)。

To just see which branches are merged or not with a particular branch, I found Jakub's reply most useful, and the related command: 要查看哪些分支与特定分支合并,我发现Jakub的回复最有用,以及相关命令:

git branch --no-merged

From git help: 从git帮助:

With --no-merged only branches not merged into the named commit will be listed. 使用--no-merged时,仅列出未合并到命名提交的分支。

If you have access to TortoiseSVN and the repo is version 1.5 or later, you could look at repository graph it generates. 如果您有权访问TortoiseSVN并且repo是1.5或更高版本,您可以查看它生成的存储库图。 However SVN in general makes it a pain to track merges. 然而,SVN通常会使跟踪合并变得很困难。

You can use svnmerge.py to manage the branches. 您可以使用svnmerge.py来管理分支。 It tells you which branches have already been merged and it only merges new revisions. 它告诉您哪些分支已经合并,它只合并新的修订版。

You could try to execute the merge with the --dry-run option and examine the output (ie see if it wants to do the merge or not). 您可以尝试使用--dry-run选项执行合并并检查输出(即查看它是否要进行合并)。

Personally, when I merge one branch with another I record the exact range of revision numbers in the commit message. 就个人而言,当我将一个分支与另一个分支合并时,我在提交消息中记录了修订号的确切范围。

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

相关问题 告诉 svn(乌龟)某个分支已经合并 - Telling svn (tortoise) that a certain branch has already been merged 我在git的错误分支上创建了一个分支,并将旧分支合并到master中,如何从另一个分支中删除提交? - I created a branch off of the wrong branch in git and already merged the old branch into master, how do I remove the commits from the other branch? 当Tortoise SVN没有合适的标签时,如何导出已经删除的子树? - How do I export a subtree that has already been deleted when there's no suitable tag with Tortoise SVN? 如何重新集成分支,覆盖尚未合并到分支的主干更改? - How to reintegrate branch, overwriting trunk changes that has not been merged into branch? SVN将已经合并的分支合并到主干 - SVN merge an already merged branch to trunk 如何使用Git SVN fetch获取单个分支? - How do I fetch a single branch using Git SVN fetch? 如何使用git-svn将svn干线添加为git分支? - How do I add an svn trunk as a git branch using git-svn? 如何使用SVN在Eclipse中查看合并分支的历史记录? - How can I see the history of a merged branch in Eclipse using SVN? 如何判断 svn 工作区是否已“切换”? - How do I tell if an svn workspace has been 'switched'? 我怎么知道分支RC-1中的修订版247389是否合并到主干中 - how do i know if a revision 247389 in branch RC-1 was merged into trunk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM