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
Last updated