Tips use of Git Rebase merge commit command

Want more articles can visit my blog - Code endless .

In the daily development process, we may have a function many times submitted. And development of our company is not allowed to be submitted directly to the company warehouse code, need to fork to his warehouse and then merge the past, this will lead to pull the code will have a lot of commit, commit these there is not much practical significance. Submit records too much can lead to code review very difficult, so today we have to introduce a very useful command - git rebase, it may be combined into a submission submitted several times, here we take a look at this show to witness the operation of it.

ready

First, we need to prepare a premise environment:
1. Initialize a git repository.

mkdir git-test
cd git-test
git init

2. Create a README.md file.
3. Create a number of submission (> 1).
We execute git log command will get the following results, a total of three times to submit records, we will git rebase command will be submitted after the two merged into one commit:

$ git log
commit 8d27ccf975e5ce4af8fd12fa75534b78fdc5b065 (HEAD -> master)
Author: 码无止境 <[email protected]>
Date:   Sun Jun 16 18:00:57 2019 +0800

    第三次提交

commit c953ae97af01e49d7f0ad959b42b91334a6726f3
Author: 码无止境 <[email protected]>
Date:   Sun Jun 16 18:00:30 2019 +0800

    第二次提交

commit 53407186cedef4be98d6001a69ee33d3a8d745fc
Author: 码无止境 <[email protected]>
Date:   Sun Jun 16 18:00:06 2019 +0800

    第一次提交

Merge commit record

1. First we execute git rebase -i HEAD ~ 3, where the merger HEAD ~ 2 represented twice submitted recently, command execution will enter into a vi editor page, as shown below:
Merge commit vi editing interface

2. After the content is edited:

p c953ae9 第二次提交
s 8d27ccf 第三次提交

3. After editing, save (: wq)

4. Then will enter into an editing interface information submitted (vi editor), I wrote "merge commit", the last time we see the merger submitted and the time second submission has been consolidated on behalf of the above is the third time submitted merged into its second submission.

5. Save the message after the successful implementation, we then execute the following command to view the git log, you will find the following results

$ git log
commit b1ab9f0af528aa96c333b2287c85d06e9fea891b (HEAD -> master)
Author: 码无止境 <[email protected]>
Date:   Sun Jun 16 18:00:30 2019 +0800
    合并提交

    第二次提交

    第三次提交

commit 53407186cedef4be98d6001a69ee33d3a8d745fc
Author: 码无止境 <[email protected]>
Date:   Sun Jun 16 18:00:06 2019 +0800

    第一次提交

Several command of the combined presentation

  • pick: Normal is selected
  • reword: Select and modify the information submitted;
  • edit: check, will be suspended when the rebase, allows you to modify this commit
  • squash: selected, will be merged with the current commit a commit
  • fixup: the squash same, but it does not save the information submitted by the current commit
  • exec: execute shell commands Other

Guess you like

Origin www.cnblogs.com/endless-code/p/11129897.html