Git rebase and Git merge are both used to fetch from a branch and merge into the current branch, but they work differently

Chestnut scene:

You are working on new features in the feature branch, and at the same time there are new commits in the Master branch.

To merge new submissions on master into your feature branch, you have two options

merge

git checkout feature
git merge master
Copy the code

or

git merge master feature
Copy the code

Git automatically generates a new commit(merge commit)

Marge features: Automatically creates a new COMMIT

If a conflict occurs during the merge, you only need to modify it and commit again

Advantages: Records the actual COMMIT, including details of each branch

Disadvantages: Because every merge automatically generates a merge commit, git GUI tools can be used to make branches messy, especially if the commit is frequent.

rebase

It’s essentially base to base to base to base what is base to base? Find a common ancestor

git checkout feature
git rebase master
Copy the code

The rebase operation does not generate new nodes, but fuses the two branches into a linear operation.

Rebase features: Merges previous commit histories advantages: a more concise project history is obtained, eliminating merge commit disadvantages: if merge code problems occur, it is not easy to locate because of the re-write history