DEV Community

Cover image for How to Split a Commit in Git
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

How to Split a Commit in Git

This article was originally published on bmf-tech.com.

Overview

A note on the steps to split a commit.

Steps

# Specify where you want to split and rebase. Set the target commit to edit.
git rebase -i HEAD~5

# Unstage
git rebase HEAD~

# Recommit the unstaged changes at the desired granularity.
git add & git commit

# Once the commit is complete, continue the rebase
git rebase --continue

# Check the log
git log

# Force push
git push -f origin HEAD
Enter fullscreen mode Exit fullscreen mode

This should allow you to split the commit.

Top comments (0)