Explore Courses Blog Tutorials Interview Questions
+2 votes
in DevOps and Agile by (19.4k points)
Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it's been committed to the local repository?

1 Answer

+1 vote
by (27.5k points)
edited by

Step 1: Start with a clean working directory and perform git status to see if there's any pending modification, deletion, or addition.

Step 2: Select the commit(s) you want to split. Here's a guide to split different commits:

Splitting the most recent commit:

git reset HEAD~a

Okay, now commit the pieces individually in the usual way, producing as many commits as you need.
Splitting a commit farther back:
This requires rebasing. Say, it's only 3 commits back, then run the following command,

git rebase -i HEAD~3

If it's farther back in the tree, than you want to count, then

git rebase -i 123abc~

Here, 123abc is the SHA1 of the commit you want to split up.

For more information please go through the following tutorial to get more info about git:



Browse Categories