This post explains how to combine git commits by using git rebase and git squash.
Let's assume that we have a couple of commits as follows. --oneline gives the short version of git log output.
Let's assume we want to squash the edits to file-B together as one commit. By using git rebase, the history will be rewritten.
The above command will open the editor with commit info up to the specified commit. Enter the Insert mode and edit the log as follows:
Save and exit the editor and that's it! Check the commit logs again to ensure the results.
If you have already pushed your changes to a remote, you might need to force push your changes.
That's it! Let me know if you encounter any problems or have any comments. Cheers!
Let's assume that we have a couple of commits as follows. --oneline gives the short version of git log output.
$ git log --oneline c123456 Edit file-B again b234567 Edit file-B a012345 Edit file-A
Quick tips: vim commands
- :wq - to save and exit
- i - to enter Insert mode
- Esc - to enter Command mode from Insert mode
Let's assume we want to squash the edits to file-B together as one commit. By using git rebase, the history will be rewritten.
$ git rebase -i a012345
The above command will open the editor with commit info up to the specified commit. Enter the Insert mode and edit the log as follows:
pick b234567 Edit file-B squash c123456 Edit file-B again
Save and exit the editor and that's it! Check the commit logs again to ensure the results.
If you have already pushed your changes to a remote, you might need to force push your changes.
git push --force
That's it! Let me know if you encounter any problems or have any comments. Cheers!