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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
git rebase -iwill do it.First, start with a clean working directory:
git statusshould show no pending modifications, deletions, or additions.Now, you have to decide which commit(s) you want to split.
A) Splitting the most recent commit
To split apart your most recent commit, first:
Now commit the pieces individually in the usual way, producing as many commits as you need.
B) Splitting a commit farther back
This requires rebasing, that is, rewriting history. To specify the correct commit, you have several choices:
If it is three commits back, then
where
3is how many commits back it is.If it is farther back in the tree than you want to count, then
where
123abcdis the SHA1 of the commit you want to split up.If you are on a different branch (e.g., a feature branch) that you want to merge into
master:When you get the rebase edit screen, find the commit you want to break apart. At the beginning of that line, replace
pickwithedit(efor short). Save the buffer and exit. Rebase will now stop just after the commit you want to edit. Then:Commit the pieces individually in the usual way, producing as many commits as you need.
Finally