about commit #169101
-
Select Topic AreaQuestion Feature AreaIssues BodyHow can I squash multiple commits into one commit before merging a pull request on GitHub? Guidelines |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Make sure your branch is up to date with the main (or your base branch). git rebase -i HEAD~N Replace N with the number of commits you want to squash (for example, if you want to squash your last 3 commits, use HEAD~3). git push -f origin your-branch-name Now your commits are squashed into one! |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Thisath345, thanks for posting in GitHub Discussions! I've gone ahead and moved this post to our I will go ahead and close this discussion as you have your question answered. |
Beta Was this translation helpful? Give feedback.
Make sure your branch is up to date with the main (or your base branch).
2. Run:
git rebase -i HEAD~N
Replace N with the number of commits you want to squash (for example, if you want to squash your last 3 commits, use HEAD~3).
3. In the interactive editor that pops up, keep "pick" for the first commit and change "pick" to "squash" (or "s") for the others you want to combine.
4. Save and close the editor.
5. Git will open another editor to combine commit messages. Edit as desired, then save and close.
6. Push your changes with force:
git push -f origin your-branch-name
Now your commits are squashed into one!