- Published
- Author
- Nived HariSystem Analyst
Combining Commits with Git Squash
Squashing commits allows us to combine multiple related commits into a single one, helping to keep the commit history clean.
Let's say if we want to combine 3 separate commits which are related to same thing into one clean commit,
1. Checkout the branch
2. Run the following command
3. Modify the rebase file. Git will open a text window with last 3 commits
•
• To squash the second and third commits into the first one, change
4. After we save and exit, another text editor will pop-up with commit messages
Simply saving this will result in a single commit with a commit message that is a concatination of all 3 messages.
We can choose which one we want, or we can create a new message entirely.
5. Complete the Rebase
After saving, we now have a single commit representing the previous three.
#git #rebase
Squashing commits allows us to combine multiple related commits into a single one, helping to keep the commit history clean.
Let's say if we want to combine 3 separate commits which are related to same thing into one clean commit,
1. Checkout the branch
Code
git checkout branch-name2. Run the following command
Code
git rebase -i HEAD~33. Modify the rebase file. Git will open a text window with last 3 commits
Code
pick 7f9d4bf first commit
pick 3f8e810 second commit
pick ec48d74 third commit•
pick means to keep the commit as is.• To squash the second and third commits into the first one, change
pick to squash / s for those commits.4. After we save and exit, another text editor will pop-up with commit messages
Code
# This is a combination of 3 commits.
# The first commit message:
fix for bug
# Commit message for #2:
Updated this
# Commit message for #3:
Added comments & updated READMESimply saving this will result in a single commit with a commit message that is a concatination of all 3 messages.
We can choose which one we want, or we can create a new message entirely.
5. Complete the Rebase
After saving, we now have a single commit representing the previous three.
#git #rebase