0

I have 10 commit on remote and local main branch(they are in sync). Now I want to combine these commits into 1 or 2 commits in my local repository and push the same changes into remote repository(Github).

Local & Remote

Hashcode | Commit Message
------------------------
commit10 basic html page
commit9 add style <H1> tag with red color
commit8 add write hello world in <h1> tag 
commit7 add <h1> tag
commit6 add <p> tag
commit5 add bgcolor
commit4 add <body> tag
commit3 add <title> tag
commit2 add <html> tag
commit1 add index.html

As you can see the commits from commit2 to commit9 are not that helpful. It could have been done in a single commit. How do i keep the changes made by these commits but delete the commit messages so that the remote repository is not cluttered with unnecessary commit messages.

I have tried git reset commit1 then git add index.html after that git commit -m "basic html page"

Required result after pushing the changes to remote repository

Local & Remote

commit2 add basic html page
commit1 add index.html

1 Answers1

0

This is called commit squashing. Example to squash the last 9 commits:

git reset --soft HEAD~9 // go back 9 commits
git add index.html
git commit -m "add basic html page"

You will find more information in this question: Squash my last X commits together using Git

HiroCereal
  • 550
  • 1
  • 11