Splitting Git Commits
Something I periodically do is split up a commit into multiple commits. I am documenting it here where I can find it fast.
Break up most recent commit
To reset the most recent commit:
git reset HEAD~
This reverts the commit. Commit individual or groups of files in multiple commits.
What if your commit isn't the most recent one?
Use an interactive rebase to commit things further back. Follow these steps:
Find the commit hash with either
Start a rebase with the commit hash replacing
git rebase -i HASH
In the rebase edit screen that comes up, find the line with the commit you want to split. Replace
Save and close the rebase edit screen
Reset to the previous commit with
git rebase HEAD~
Create new commits using the files and writing the messages that go along with them
git add file/to/be/committed.xyz git commit -m "Enhance the algorithm to support Mars rovers"
- Finish the rebase:
git rebase --continue
Tags: git howto