Compare Two Branches Sourcetree

admin
  • Status:Closed(View Workflow)
  • Fix Version/s: None
  • Labels:
  1. Sourcetree Compare Two Branches
  2. Compare 2 Git Branches
  3. Sourcetree Diff
  4. Gitkraken Compare 2 Branches
  • Feedback Policy:

    Our product teams collect and evaluate feedback from a number of different sources. To learn more about how we use customer feedback in the planning process, check out our new feature policy.

Sometimes I have to compare different commits and branches. I know that I can do this in the log view by selecting two commits with Cmd, but this is very annoying.

I am using also SmartGit which has some features which I am missing at Sourcetree:

In this case, your development history has diverged from some older point. Because the commit on the branch you’re on isn’t a direct ancestor of the branch you’re merging in, Git has to do some work. In this case, Git does a simple three-way merge, using the two snapshots pointed to by the branch tips and the common ancestor of the two. From the left-side menu items in Sourcetree, hover your mouse over the right side of the Branches label so that the word Show appears. When Show appears, click it. Under the Branches heading, you will see the two branches for this repository, the main branch, and the wish-list branch. The main branch for a Git repository is called master.

Recall that when you merge one branch into another, a new merge commit is created that points to both branches. In fact, a merge commit may have two or more parents as it’s possible to merge multiple branches into one at the same time. But in most cases a merge commit has exactly two parents. SourceTree creates “(no branch / rebasing )”, okay so when I resolve my conflict, I commit it, then “HEAD” Appears with my resolved file, but if I switch to my Feature Branch it doesn’t appear to be rebased, when I get prompted to Continue, this seems to do thing and I find myself back to square 1. Hunk is a term related to diff: The format starts with the same two-line header as the context format, except that the original file is preceded by '-' and the new file is preceded by '. Following this are one or more change hunks that contain the line differences in the file.

  1. In SmartGit I can select a tag or branch in the repository view and use the context menu (reveal commit) to jump to a tag or commit. After this operation the corresponding the corresponding commit will be selected in the log view.
  2. After this operation I can select a different branch and use the context menu 'compare against selected commit'. This is really helpful. In SourceTree this operation is not possible. Currently you can only select a branch, then you have to select the commit in the log view and the context menu allows only the diff against the current.
  3. The log view can be quite long, therefore a filtering of the log would be great. In SmartGit you can search also for tags in the commit view, this means if you want to diff to tags, you just have to use a corresponding search pattern. Afterwards the two tags can be selected in the filtered view (without annoying scrolling in the logs) and that is really easy.

I attached some screenshot to illustrate the behavior.

Attachments

  1. compare_with_selected.png
    35 kB
  2. reveal_commit.png
    39 kB
  3. search_commit.png
    43 kB
Votes:
0Vote for this issue
Watchers:
2Start watching this issue

Customize External Source Control to Use MATLAB for Diff and Merge

You can customize external source control tools to use the MATLAB® Comparison Tool for diff and merge. If you want to compare MATLAB files such as live scripts, MAT, SLX, or MDL files from your source control tool, then you can configure your source control tool to open the MATLAB Comparison Tool. The MATLAB Comparison Tool provides tools for merging MathWorks® files and is compatible with popular software configuration management and version control systems. You can use the automerge tool with Git™ to automatically merge branches that contain changes in different subsystems in the same SLX file.

To set up your source control tool to use MATLAB as the application for diff and merge, you must first determine the full paths of the mlDiff, mlMerge, and mlAutoMerge executable files, and then follow the recommended steps for the source control tool you are using.

Finding the Full Paths for MATLAB Diff, Merge, and AutoMerge

To get the required file paths and enable external source control tools to reuse open MATLAB sessions, run this command in MATLAB:

This command sets the MATLAB preference, under Comparison, called Allow external source control tools to use open MATLAB sessions for diffs and merges.

This command also displays the file paths to copy and paste into your source control tool setup:

  • On Windows®:

  • On Linux®:

  • On Mac:

Compare Two Branches Sourcetree

where matlabroot is replaced with the full path to your installation, for example, C:Program FilesMATLABR2020b.

Note

Your diff and merge operations use open MATLAB sessions when available, and only open MATLAB when necessary. The operations only use the specified MATLAB installation.

Compare Two Branches Sourcetree

Integration with Git

Command Line

To configure MATLAB diff and merge tools with command-line Git:

  1. Run this command in MATLAB.

    This command displays the full paths of the mlDiff, mlMerge, and mlAutoMerge executable files. It also automatically populates the global .gitconfig file. For example:

    Note

    You need to do step 1 only once for your Git setup.

  2. Configure your repository to use the mlAutoMerge executable file. Open the .gitattributes file in your repository and add:

    Now, when you merge branches that contain changes in different subsystems in the same SLX file, MATLAB handles the merge automatically.

To run the MATLAB diff and merge tools from command-line Git, use git difftool and git mergetool:

  • To compare two revisions of a model using the MATLAB diff tool, type:

    If you do not provide revision IDs, git difftool compares the working copy to the repository copy.

    If you do not specify which model you want to compare, command-line Git will go through all modified files and ask you if you want to compare them one by one.

  • To resolve a merge conflict in a model using the MATLAB merge tool, type:

    If you do not specify which model you want to merge, command-line Git will go through all files and ask you if you want to merge them one by one.

SourceTree

SourceTree is an interactive GUI tool that visualizes and manages Git repositories for Windows and Mac.

  1. Configure the MATLAB diff and merge tools as SourceTree external tools:

    1. With SourceTree open, click Tools > Options.

    2. On the Diff tab, under External Diff / Merge, fill the fields with the following information:

  2. Configure your repository to automerge changes in different subsystems in the same SLX file using the mlAutoMerge executable file:

    1. Open the global .gitconfig file and add:

    2. Open the .gitattributes file in your repository and add:

Tip

Customize the full path of the mlDiff, mlMerge, and mlAutoMerge executables to match both the MATLAB installation and the operating system you are using. For more information, see Finding the Full Paths for MATLAB Diff, Merge, and AutoMerge.

To use the MATLAB diff tool from within SourceTree, right-click a modified file under Unstaged files and select External Diff.

To use the MATLAB merge tool when SourceTree detects a merge conflict, select the Uncommitted changes branch, right-click a modified file, and select Resolve Conflicts > Launch External Merge Tool.

Integration with SVN

TortoiseSVN

Sourcetree Compare Two Branches

With TortoiseSVN, you can customize your diff and merge tools based on the file extension. For example, to use MATLAB diff and merge tools for SLX files:

  1. Right-click in any file explorer window and select TortoiseSVN > Settings to open TortoiseSVN settings.

  2. In the Settings sidebar, select Diff Viewer. Click to specify the diff application based on file extensions.

  3. Click and fill the fields with the extension and the mlDiff executable path:

  4. Click and repeat the same steps to add another file extension.

  5. In the Settings sidebar, select Diff ViewerMerge Tool. Click to specify the merge application based on file extensions.

  6. Click and fill the fields with the extension and mlMerge executable path:

  7. Click and repeat the same steps to add another file extension.

You can now use the MATLAB tools for diff and merge the same way you would use the TortoiseSVN default diff and merge applications.

Note

Automerging binary files with SVN , such as SLX files, is not supported.

Integration with Other Source Control Tools

Perforce P4V

Compare 2 Git Branches

With Perforce® P4V, you can customize your diff and merge tools based on the file extension. To use MATLAB diff and merge tools for SLX files, for example:

  1. In Perforce, click Edit > Preferences.

  2. In the Preferences sidebar, select Diff. Under Specify diff application by extension (overrides default), click .

  3. In the Add File Type dialog box, enter the following information:

  4. Click .

    Install anydesk command line. AnyDesk Software GmbH was founded in 2014 in Stuttgart, Germany and has gone worldwide, with subsidiaries in the US and China. In May 2018, AnyDesk secured 6.5 million Euros of funding in a Series A round led by EQT Ventures. Another round of investment in January 2020 brings AnyDesk to over 20 million Dollars of combined funding.

  5. In the Preferences sidebar, select Merge. Under Specify merge application by extension (overrides default), click .

  6. In the Add File Type dialog box, enter the following information:

  7. Click and repeat the steps for other file extensions.

Sourcetree Diff

Tip

Customize the full path of the mlDiff and mlMerge executables to match both the MATLAB installation and the operating system you are using. For more information, see Finding the Full Paths for MATLAB Diff, Merge, and AutoMerge.

You can now use the MATLAB tools for diff and merge the same way you would use the Perforce default diff and merge applications.

Gitkraken Compare 2 Branches

Related Topics