Branching and Merging SWEN-610 Introduction to Software - - PowerPoint PPT Presentation

branching and merging
SMART_READER_LITE
LIVE PREVIEW

Branching and Merging SWEN-610 Introduction to Software - - PowerPoint PPT Presentation

Branching and Merging SWEN-610 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Version control branching supports the ability to manage software releases. At the end of a sprint,


slide-1
SLIDE 1

SWEN-610 Introduction to Software Engineering

Department of Software Engineering Rochester Institute of Technology

Branching and Merging

slide-2
SLIDE 2

Version control branching supports the ability to manage software releases.

  • At the end of a sprint, the team will want to include

done stories but exclude incomplete stories.

  • This cannot be done when all of the stories are

developed in the master branch.

  • Feature branching is a technique that creates a

branch for each story during development.

  • Changes are isolated in specific branches.
  • When the story is done, the feature branch is merged

into the master branch.

  • The master branch never receives incomplete work.
  • Thus master is always the most up-to-date, working

increment.

2

slide-3
SLIDE 3

An example sprint at the end.

3 In Dev In Test Ready for Test Sprint 2 Done

S3 S4 S6

Sprint 2 Backlog

S8 (5)

Sprint 1 Done

S1 S2 S5

slide-4
SLIDE 4

The life cycle of the feature branch is tied to the development cycle of the story.

4

slide-5
SLIDE 5

Two developers collaborate on a story by working

  • n the same feature branch.
  • The developers share code on a story by syncing

to the same remote feature branch.

5

slide-6
SLIDE 6

Two interdependent stories can share changes across two branches.

  • The first story branch is created from master and

the second branch is created from the first.

6

Not shown are the coordinating remote branches

slide-7
SLIDE 7

Merging happens a lot and usally goes well; other times not so much.

  • Every time you sync with the remote a merge
  • ccurs.
  • A "fast forward" is when your local branch has no

additional changes and your local branch is just moved to the commit point of the remote.

  • If your local changes do not overlap with the

changes fetched from the remote, then an automatic merge is possible.

  • A conflict occurs when there is at least one file

with overlapping changes.

7

slide-8
SLIDE 8

Here's an example of a merge conflict.

  • Imagine there is a bug in a method:

/** * Calculate a half-off discount. */ public float calculateDiscount(final float cost) { return cost * 2; }

  • Independently, two developers fix this bug:
  • Betty did this:

return cost / 2;

  • Sam did this:

return cost * 0.5f;

8

slide-9
SLIDE 9

When a conflict occurs git reports the affected files.

  • When Sam merges in the code from Betty:

➔ git merge dev1 Auto-merging src/main/java/com/example/model/Promotion.java CONFLICT (content): Merge conflict in src/main/java/com/example/model/Promotion.java Automatic merge failed; fix conflicts and then commit the result.

  • Sam now has to fix the conflict; seen here:

public float calculateDiscount(final float cost) { <<<<<<< HEAD return cost * 0.5f; ======= return cost / 2; >>>>>>> dev1 }

9

The HEAD in Sam's workspace. This is the code from Betty's branch.

slide-10
SLIDE 10

Resolving a simple text conflict is often easy.

  • Determine the best solution, and remove the other

solution and the marker text.

/** * Calculate a half-off discount. */ public float calculateDiscount(final float cost) { return cost / 2; }

  • Then add (and commit) the resolved change:

git commit –am "Fixed discount calculation"

  • Push it.

10

slide-11
SLIDE 11

There are other challenges when merging.

  • Binary files
  • Document files, such as Word or Excel, are binary

and cannot be merged.

  • Such files should have an owner who is responsible

for moderating changes.

  • And a clear protocol for permitting team members

access.

  • Tree structures
  • Types:

 file name changes  directory name changes  moving files and directories

  • Why:

 Java package changes  Class name changes

11

slide-12
SLIDE 12

To minimize the number of times when conflicts will not resolve easily, follow several guidelines.

  • 1. Keep code lines short; break up long

calculations.

  • 2. Keep commits small and focused.
  • 3. Minimize stray edits.
  • 4. If multiple developers are collaborating on a

feature, each developer should sync with the remote branch regularly.

Merge in the remote branch and then push to it, if you have changes.

  • 5. If development of a feature is taking a long time,

back merge master to sync completed features for this sprint into the feature branch.

12