My repository has one branch and a number of different commits. The initial commit contains some code. I want to create a pull request of current branch but to an earlier version then the initial commit so that I can view the whole relevant code that has been added. How can I split a commit to 2?
Asked
Active
Viewed 849 times
1 Answers
4
You can follow the procedure described in this answer to "How to break a previous commit into multiple commits" with the exception that you need to add the --root
switch, since you want to modify the first commit in your branch.
From the documentation:
--root
Rebase all commits reachable from <branch>, instead of limiting them with an <upstream>. This allows you to rebase the root commit(s) on a branch.
For example, assuming you wanted to modify the initial commit in master
, you would say:
git checkout master
git rebase -i --root

Community
- 1
- 1

Enrico Campidoglio
- 56,676
- 12
- 126
- 154
-
When I tried this I found that this requires `git reset HEAD~` on the root commit which hits an error: `unknown revision of path not in working tree`. – gngdb Sep 05 '20 at 22:28
-
1We found a way to do this by adding a dummy commit and reordering, then removing that dummy commit. Details here: https://gist.github.com/gngdb/52db51778d814cc48fd2ec94d7727beb – gngdb Sep 16 '20 at 21:44