Can you tell me how git can avoid confusing submission records of dev branches when merging dev branches to master?

  git, question

There are dev development branch and master main branch. After the development of dev branch is completed, when merging master branches, the chaotic commit submission records on dev will be taken away.

Can you keep only the latest commit record or create only a new commit record when the dev branch is merged into the master branch?

Ask big advice T_T

Of course, this is also a common problem, so there are corresponding operations in git-Compressed submission. As the landlord said, the information you submitted in the dev branch is very messy or unreasonable. at this time, you really want to put themCompressionSubmit in one submission. There are two methods below. The first method is simple and easy to understand.

  • Method 1: Use reset command

resetCommands can do some interesting things. Compressed submission is one of them.

First, you should be able to find the first commit on the dev branch, get its commit hash value, and then use the following command:

git reset --soft <hash-code-of-first-commit>

Of course, if you don’t want to compress many submissions, for example, only three, you can use relative positions.HEAD~3.

Then submit. In the submission information, you can rearrange your submission information, thus compressing all submissions on dev into one submission.

git commit

The specific principle can be referred to Pro Git. If necessary, I can explain it in detail here.

  • Method 2: Use Variable Base Command

Since many people are not familiar with the variable base command and it is more difficult to understand the relative reset command, this is only an alternative. However, you should know that the variable base command can not only compress the submission, but also change the submission history.

Similarly, you need to get the hash value of the dev branch submitted for the first time.

rungit rebaseCommand and specify-iOptions:

git rebase -i <hash-code-of-first-commit>

Git then opens a script file similar to the following:

pick af0ddef whitespace yo
 pick 0c04f10 Prepare for 2.19.0
 pick 8264ac4 Remove a duplicated world
 
 # Rebase 9ee2d6f..8264ac4 onto 9ee2d6f (3 command(s))
 #
 # Commands:
 # p, pick = use commit
 # r, reword = use commit, but edit the commit message
 # e, edit = use commit, but stop for amending
 # s, squash = use commit, but meld into previous commit
 # f, fixup = like "squash", but discard this commit's log message
 # x, exec = run command (the rest of the line) using shell
 # d, drop = remove commit
 #
 # These lines can be re-ordered;  they are executed from top to bottom.
 #
 # If you remove a line here THAT COMMIT WILL BE LOST.
 #
 # However, if you remove everything, the rebase will be aborted.

Next, you need to modify the script according to your own needs, and the usage of the command has been indicated in the comments. Since we need to compress all submissions to the first submission, we need to change the script to something like this:

pick af0ddef whitespace yo
 squash 0c04f10 Prepare for 2.19.0
 squash 8264ac4 Remove a duplicated world
 
 # Rebase 9ee2d6f..8264ac4 onto 9ee2d6f (3 command(s))
 #
 # Commands:
 # p, pick = use commit
 # r, reword = use commit, but edit the commit message
 # e, edit = use commit, but stop for amending
 # s, squash = use commit, but meld into previous commit
 # f, fixup = like "squash", but discard this commit's log message
 # x, exec = run command (the rest of the line) using shell
 # d, drop = remove commit
 #
 # These lines can be re-ordered;  they are executed from top to bottom.
 #
 # If you remove a line here THAT COMMIT WILL BE LOST.
 #
 # However, if you remove everything, the rebase will be aborted.

After a little thought, you should be able to understand the reason.

After modification, save and exit, then git will give you the opportunity to edit the submission again. if necessary, you can change the submission:

# This is a combination of 3 commits.
 # The first commit's message is:
 whitespace yo
 
 # This is the 2nd commit message:
 
 Prepare for 2.19.0
 
 # This is the 3rd commit message:
 
 Remove a duplicated world
 
 # Please enter the commit message for your changes. Lines starting
 # with '#' will be ignored, and an empty message aborts the commit.
 #
 # Author:    Josh Nichols  <technicalpickles@github.com >
 # Date:      Fri May 6 18:51:49 2016 -0400
 #
 # interactive rebase in progress;  onto 9ee2d6f
 # Last commands done (3 commands done):