主要内容

Branch and Merge withGit

Create Branch

  1. From within your Git™ repository folder, right-click the white space of the Current Folder browser and selectSource Control>Branches. In the Branches dialog box, you can view, switch, create, and merge branches.

    Tip

    You can inspect information about each commit node. Select a node in theBranch Browserdiagram to view the author, date, commit message, and changed files.

    TheBranch Browserin this figure shows an example branch history.

  2. Select a source for the new branch. Click a node in theBranch Browserdiagram, or enter a unique identifier in theSourcetext box. You can enter a tag, branch name, or a unique prefix of the SHA1 hash (for example,73c637to identify a specific commit). Leave the default to create a branch from the head of the current branch.

  3. Enter a name in theBranch nametext box and clickCreate.

  4. To work on the files on your new branch, switch your project to the branch.

    In theBranchesdrop-down list, select the branch you want to switch to and clickSwitch.

  5. Close the Branches dialog box and work on the files on your branch.

Switch Branch

  1. From within your Git repository folder, right-click the white space of the Current Folder browser and selectSource Control>Branches.

  2. In the Branches dialog box, in theBranchesdrop-down list, select the branch you want to and clickSwitch.

  3. Close the Branches dialog box and work on the files on your branch.

Compare Branches

From within your Git repository folder, right-click the white space of the Current Folder browser and selectSource Control>Branches.

  • To examine differences in a file between the current revision and its parent, right-click a file in the tree underDifferences from parentand selectShow Difference.

  • To examine differences in a file between any two revisions including revisions on two different development branches, hold theCtrlkey and select the two different revisions. Right-click a file in the tree underDifferences from selectionand selectShow Difference.

MATLAB®opens a comparison report. You can save a copy of the selected file on either revision. Right-click a file and selectSave Asto save a copy of the file on the selected revision. SelectSave Original Asto save a copy of the file on the prior revision. This is useful if you want to test how the code ran in previous revisions or on other branches.

Merge Branches

To merge any branches:

  1. From within your Git repository folder, right-click the white space of the Current Folder browser and selectSource ControlandBranches.

  2. In the Branches dialog box, from theBranchesdrop-down list, select a branch you want to merge into the current branch, and clickMerge.

  3. Close the Branches dialog box and work on the files on your branch.

If the branch merge causes a conflict that Git cannot resolve automatically, an error dialog box reports that automatic merge failed. Resolve the conflicts before proceeding.

Caution

Do not move or delete files outside of MATLAB because this can cause errors on merge.

Keep Your Version

  1. To keep your version of the file, right-click the file and selectMark Conflict Resolved.

  2. ClickCommit Modified Filesto commit your change that marks the conflict resolved.

视图在分支版本冲突

If you merge a branch and there is a conflict in a file, Git marks the file as conflicted and does not modify the contents. Right-click the file and selectSource Control>View Conflicts. A comparison report opens that shows the differences between the file on your branch and the branch you want to merge into. Decide how to resolve the conflict. SeeResolve SVN Source Control Conflicts.

Revert to Head

  1. From within your Git repository folder, right-click the white space of the Current Folder browser and selectSource Control>Branches.

  2. In the Branches dialog box, clickRevert to Headto remove all local changes.

删除分支

  1. In the Branches dialog box underBranch Browser, expand theBranchesdrop-down list, and select the branch you want to delete.

  2. 在最右边,点击down arrow and selectDelete Branch.

Caution

You cannot undo branch deletion.

Related Topics