Method one: merge between two branches

Git rebase Remote and local branches: Git rebase With no parameters, the default is git rebase remote and local branches

Usage scenario: Little A and little B share A remote branch. Little B submits the code several times. When little A wants to submit the code, it finds A conflict.

Git add -> git commit if A merge is performed and the conflict is resolved, git add -> git commit will appear in git log

If you use Git rebase, there is no Merge related commit in git log, and the commit history is a straight line. The idea is that Git will move our current commit after a push

Other branches and current branches: Git rebase Other branches Local branches

Git merges a local branch with a commit. Git merges a local branch with a commit

Method two: merge some branches

Git rebase — Onto other Branches Local branch Sub-branches of a local branch

Commit between a local branch and a sub-branch of a local branch will not appear in commit after git rebase

Usage Scenarios:

  1. Cut out Feature1 and Feature2 from the Master branch
  2. Feature2 was committed three times
  3. Cut a new branch from Feature2 feature2/ Child
  4. Feature2 / Child commit once

Git rebase –onto Feature1 Feature2 Feature2 / Child

It will only merge the feature2/ Child Commit once, but will not carry the feature2 COMMIT three times

Method 3: Modify some commits on a branch

git rebase -i startCommitID

Use this command if you want to modify a COMMIT or commit, preferably before the current code pushes to a remote branch.

Before each commitId, you can run commands to merge commitId, delete commitId, and modify commitId.

The s command cannot be used on the first line

Git rebase -i 2a5eb63, for example, displays a commit after 2a5eb63

Git push -f git push -f git push -f git push -f git push -f

Finally, note that after each conflict is resolved, git add – > git rebase –continue(or some other command)