Git — merge commit

1.git rebase -i

(same as git rebase)

Use the git rebase -i command

git rebase -i HEAD~2

Execute and jump to a new screen:

Git rebase -i is used to modify the commit information. If you change pick to edit, you can modify the commit information. If you change pick to edit, you can merge commit information.

git log

We merge commit: h, g, and e into a single: merged F.

After we execute, we go into edit mode and change pick to S (squash).

Merge three and squash two of them

Save and exit the edit mode. The following interface is displayed.

By default, e, g, and h are merged into a single commit, which is shown in the red box. You can edit it and change it to the desired commit

2. git reset

Git reset –soft commit_id (commit_id = new commit_id of remote repository, commit_id = new commit_id of remote repository, commit_id = new commit_id) Run git add(if necessary) and run git commit -m “MSG” to commit once. Git add and reset all code changes in the staging area and workspace. Git commit does not exist.

Example: Merge COMMIT: e, f, and g into a new COMMIT: EFG

Git reset –soft d7e5d51 (d7e5d51 indicates commit_id for COMMIT D)

Git commit -m “efg

3. git merge –squash

(Squash on GitLab?) Example: Master merges br1 branch code, br1 has had multiple commits.

Git checkout master git merge –squash br1

// -- Squash suspends commit commit, otherwise a merge automatically commits commitCopy the code

Git commit -m “squash_msg

over

In terms of overall experience, method 2 is easier to understand and use. Reset-soft is recommended