How can I remove the first N commits and keep the rest of commits untouched?
In other words. I want to split the repo at the point n-th commit, pick up the commits start from n+1-th, discard the commits from 1st to n-th.
I do not know how to achieve this. Only tried git rebase
, but it did not work.
The following is what I did with git rebase
.
For example, the repo for testing is https://github.com/danistefanovic/build-your-own-x.git
Run
git rebase -i --root
Mark the first 20 commits as deleted
d 4b6d12e Initial commit d f81138e Add links to issue form d 3530d91 Update README.md d 506b834 Update README.md d 79f41aa Update README.md d f9f9113 Update README.md d 9c8f134 Add resource type d 133469b Update ISSUE_TEMPLATE d 3a47f54 Add tutorials #1 d 0271577 Add tutorial #2 d 525953b Add tutorial #3 d 2796fe5 Update ISSUE_TEMPLATE d 4f58667 Updated wrong link language from Go to Node.js d 0c525a7 Add tutorial #5 d 0484fca Add OS: Build a minimal multi-tasking kernel for ARM d 457d5bb Add tutorial #9 d 41ba7fc Add tutorial d dfbbf0f Add tutorial #11 d b76dad5 Add tutorial #12 d cd3bd26 Add tutorial #13 pick c5f6c94 readme: Add my tutorial on shell pick 1f3c285 Add a minimal interpreter, compiler (x86/Arm) and JIT compiler ...
No luck. I have to handle conflicts manually as show blow.
$ git rebase -i --root error: could not apply c5f6c94... readme: Add my tutorial on shell Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply c5f6c94859d852797c26d815e438e6a697c137a9... readme: Add my tutorial on shell
Update
Duplicated with Remove / cut off Git's revision / commit history
But did not find a way to keep the timestamps.