简体   繁体   中英

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?

Is Mercurial or Git any more intuitive than SVN for this?

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.

On git, you can use git log to ask if one branch includes another:

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

If nothing is returned, topic has been merged.

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 branch -a --contains feature

will show all branches (with -a , that includes remote branches) that have merged the given feature.

git show-branch will show lots of details of the relationships between branches. 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.

Let's say you have reintegrated two branches in the trunk, you can check with (replace with your 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.

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).

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.).

To just see which branches are merged or not with a particular branch, I found Jakub's reply most useful, and the related command:

git branch --no-merged

From git help:

With --no-merged only branches not merged into the named commit will be listed.

If you have access to TortoiseSVN and the repo is version 1.5 or later, you could look at repository graph it generates. However SVN in general makes it a pain to track merges.

You can use svnmerge.py to manage the branches. 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).

Personally, when I merge one branch with another I record the exact range of revision numbers in the commit message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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