Git Squash Last 2 Commits
By using the interactive rebase feature you can squash the last two commits.
For that follow the below steps:
Step 1: Switch to the branch in which you want to squash the last two commits. Run the following command which if the interactive rebase command passes the argument Head~2 specifies you want two squash the last two commits.
git rebase -i HEAD~2
Step 2: After running the above command an interactive rebase file will open which contains the commits you are about to modify. “Pick” is used at starting of each line to squash the last commit into the second-to-last commit and changes the word from “pick” to “squash” or “s” for the last commit.
pick <commit_hash_1> <commit_message_1> squash <commit_hash_2> <commit_message_2>
Save and close the rebase operation will start.
Step 3: New text editor will open where you can modify the commit messages for the new squashed commit. After changing the commit message save and closing the file the rebase operation will be completed.