The difference between merge and no-ff merge
Normally, Git
uses Fast forward
mode when merging branches, but in this mode, after deleting a branch, the branch information will be lost. If you want to force disabling Fast forward
mode, Git
will generate a new commit
on merge
, so that branch information can be seen from the branch history.
To put it simply, the ff mode will organize the branch history into a branch line, and the merged branch information cannot be seen, but the no-ff mode will display a fork node, and then you can see the information of the merged branch.
Caption
Prerequisites: The warehouse has only one file, readme.txt, and only one main branch, master
1.Create a new branch dev1
, modify readme.txt
, and submit it under the dev1 branch
git switch -c dev1
git add readme.txt
git commit -m "dev1 branch commit"
2.Go back to the master
branch and execute merge
i.e. git merge dev1
git switch master
git merge dev1
3.delete branch
git branch -d dev1
4.View logs
git log --graph --pretty=oneline --abbrev-commit
5.Create a new branch dev2
, modify readme.txt
, and submit
git switch -c dev2
git add readme.txt
git commit -m "dev2 branch commit"
6.Go back to the master
branch and execute merge
git switch master
git merge --no-ff -m "dev2 merged with mo-ff" dev2
7.delete branch
git branch -d dev2
8.View logs
git log --graph --pretty=oneline --abbrev-commit
9.Comparing the two merges, you can see the difference, the no-ff
mode will record the branch history