Skip to main content
Background Image
  1. Posts/

Git Commit Squash

·226 words·2 mins· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

If your commits on local not pushed to remote
#

combine local commits, you could follow this flow
#

Here is short video (only 3 minutes) and good explanation of git rebase -i usage.

list your local repository log

list your logs in oneline

If you want to combine these 3 commits (add6152, 3650100, 396a652) to 1 commit, execute this command

git rebase -i HEAD~3      # last three commits

list last three commits

Select which commit you want to squash (type s or squash are OK)

combine three commits to one

then press ESC, enter :wq! to save and exit.

comment out some commits message you don’t need

Comment out some commits message you don’t need, press ESC, enter :wq! to save and exit.

comment out some commits message you don’t need

Check log, you will see your local repository logs has combine to one commit

comment out some commits message you don’t need

If your commits had pushed to remote
#

combine remote commits, you could follow this flow
#

list your repository logs

list your logs in oneline

# so you can create another branch from bugfix/UNV-1234 named bugfix/UNV-1234-for-squash
xshen@dln-l-xs01 MINGW64 /c/U2GitCode/git-test (bugfix/UNV-1234)
$ git checkout -b bugfix/UNV-1234-for-squash
Switched to a new branch 'bugfix/UNV-1234-for-squash'

# combine last 2 commits
$ git rebase -i HEAD~2

change one commit from pick to squash, see the screenshot below. press ESC, enter :wq! to save and exit.

select a commit you want to squash

change commit message, for example “UNV-1234 combine all commit to one commit”, then press ESC, enter :wq! to save and exit.

comment out commit message you don’t want to display

# push your new create branch to remote.
git push -u origin bugfix/UNV-1234-for-squash

Related

Jenkins Multibranch Pipeline
·405 words·2 mins
Discusses the use of Jenkins Multibranch Pipeline to manage multiple branches in a project, enabling parallel builds for pull requests and efficient code review processes.
A Code Coverage Tool - Squish Coco use examples
·699 words·4 mins
introduction to Squish Coco, a code coverage tool, with examples of how to set it up and use it in Visual Studio for C++ projects.
Code Coverage tools of C/C++
·168 words·1 min
Code Coverage is a measurement of how many lines, statements, or blocks of your code are tested using your suite of automated tests. It’s an essential metric to understand the quality of your QA efforts.
Jenkins Linux agent configuration
·298 words·2 mins
Provides a step-by-step guide on how to configure a Jenkins Linux agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins Windows agent configuration
·544 words·3 mins
Provides a step-by-step guide on how to configure a Jenkins Windows agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.