Premise: Multiple COMMITS are made on a branch, each time pushed to a remote repository
During development, a branch is pulled from the main branch to write code. Sometimes there are so many commitments to save the current work that there are so many requests in the online repository that it is a good idea to combine multiple requests into one when merging branches. The following steps are specific:
1. Git log View all commit branches
- Only a portion may be displayed, and pressing Enter will continue to display the rest until the first committed record appears
- To exit, press the letter Q
2. Git rebase -i commitID Merge branches
- Here commitID is selected as the first commit before commitID, because it does not merge the commit of the commitID you entered, but from all subsequent commits. If you select commitID for your first commit, it will only merge from your second commit.
3. After entering, change all but the first pick to f. Save and exit
- Once in, press the letter I to enter edit mode. Press Esc to exit the editing mode, and press :wq to exit the editing mode (the colon cannot be less).
Git push -f
- After this step is complete, go to the online repository of the current operation branch and refresh it to see that a commit has been synthesized several times before. The name shows the first COMMIT. The following is the sum of several previous submissions.
Tips
About the merging method of the third step:
Git rebase -i commitID commitID is the ID of the last commit. Git rebase -i HEAD~3 HEAD~num Num is 3Copy the code