In git, rebase can edit, delete, copy, and paste a certain linear commit history. It is often used to merge commits and paste a certain commit to another branch. The syntax is "git rebase parameter [startpoint][endpoint]".
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
What is the usage of rebase in git
Rebase is a very charming command in git. Use it properly and you will greatly improve yourself. work efficiency; on the contrary, if used indiscriminately, it will cause trouble to other people in the team. Its function is briefly summarized as follows: you can edit, delete, copy, and paste a certain linear submission history; therefore, the reasonable use of the rebase command can make our submission history clean and concise!
Premise: Do not modify any commits that have been submitted to the public warehouse through rebase (except for branches you play alone)
1. Merge multiple commits into one complete commit
When we have submitted multiple times in the local warehouse, before we push the local submission to the public warehouse, in order to make the submission record more concise and clear, we hope to put the following three submission records of branches B, C, and D. Merge into a complete commit and then push to the public repository.
Now that we have added four commits on the test branch, our goal is to merge the last three commits into one commit:
Here we use the command:
git rebase -i [startpoint] [endpoint]
where -i means --interactive, which pops up an interactive interface for the user to edit and complete the merge operation, [startpoint] [endpoint] is specified An editing interval, if [endpoint] is not specified, the end point of the interval is by default the commit pointed to by the current branch HEAD (note: this interval specifies an interval that is open at the beginning and closed at the end).
After viewing the log, we run the following command:
git rebase -i 36224db
or:
git rebase -i HEAD~3
Then we will see the following interface:
The uncommented part above lists all the submissions included in our rebase operation. The comment part below is the command description provided by git for us. The pick in front of each commit id indicates the instruction type. Git provides us with the following commands:
pick: retain the commit (abbreviation: p)
reword: Keep the commit, but I need to modify the comment of the commit (abbreviation: r)
The above is the detailed content of What is the usage of rebase in git. For more information, please follow other related articles on the PHP Chinese website!