Essential Git for Scientists
  • Introduction
  • Basic Concepts
    • Version Control
    • Git
    • Repo
    • Commits
    • Branches
    • Remotes
    • GitHub
    • De-centralisation
    • Summary
  • Basic Operations
    • Install Git
    • Create a Repo
    • Make a Commit
    • Inspect a Previous Commit
    • Revert a Change
    • Make a Branch
    • Extend a Branch
    • Fast-forward merge
    • Resolve conflicts
  • Intermediate Concepts
    • Commits
    • Three Trees
    • Rebase
    • Fetch
    • Pull
    • Push
  • Advanced Concepts
    • Reset
    • Interactive rebase
    • Formatted patches
    • Blame
    • Stash
    • Log filter
  • Cookbook
    • Undo
    • Branches
    • Diff
    • Stash
    • Merge
    • Hooks
    • Squashing
    • Rebase
    • Interactive Rebase
    • LFS
    • Submodules
    • Remote
    • Force push
    • Identify merged branches
    • Formated patches
    • Apply patches
    • Interactive rebase
    • Squash commits
    • Pull rebase
    • Log
    • Blame
    • Biset
    • Reset
  • Exercise
    • Exercise 1
    • Exercise 2
Powered by GitBook
On this page
  1. Basic Operations

Fast-forward merge

As mentioned previously, there are two types of merges.

  • Fast-fowrad merge takes place when a branch is simply ahead of another branch. In this case, there's no conflict, as the longer branch includes the shorter one completely. What Git will do is to update shorter branch to the latest commit.

  • In a non-fast-forward merge, it may cause an conflict.

    • Scenario 1: both branches edit the same file, one says the patient ID is 8, the other says 10. This is a conflict and you need to step in to tell Git which one to use.

    • Scenario 2: both branches edit the same file, but different sections of a file. One changes paitent ID to 8 and the other changes the learning rate to 1e-3. In this case, no conflict occurs and Git can handle this.

This section will look at the fast-forward merge.

In the previous example, new is simply ahead of master. If we want to include the changes back to master, it will be a fast-forward merge.

We first change back to master and perform the merge using git merge <branch-name>.

λ git checkout master
Switched to branch 'master'
λ git merge new
Updating a37231a..e84601c
Fast-forward
 newfile.py | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 newfile.py

Now the commit history shows master is pointing to the lastest commit.

λ git log --oneline
e84601c (HEAD -> master, new) Added new file
a37231a Revert "Added another file"
35ac407 Added another file
ee7ebbd Print out the std dev
b1e55d3 Print out the mean
c96c526 First commit
PreviousExtend a BranchNextResolve conflicts

Last updated 1 year ago