I have a simple repository with linear history of commits, like:
[A] -> [B] -> [C] -> [D] -> [E] ...
I basically need to remove commits A and B so I thought I'd create a new repository and would like to achieve something like:
[X] -> [C] -> [D] -> [E] ...
So I created a new repository, manually created commit X that takes stores the relevant information from A and B and now need a command that will bring commits C, D, E etc. from the original repository and will put it on top of my new commit X.
How to do that?
Edit: Two problems I have with the suggested cherry-pick method are:
git branch -D myoriginalrepo/master
, it says that no such branch exists while I can clearly see those commit in my GUI tool.Not sure why you need the commit date to stay the same but here goes:
git rebase B E --onto X --committer-date-is-author-date
If B..E
aren't in the same repository as X
(as they can be if you create your fresh start in-place), you'll need to fetch them first:
git fetch <path_to_old_repos>
Of course, B
, E
and X
here mean their commit-ids if you haven't actually tagged/branched them.
You can also do something similar (although commit date won't be preserved) by rebasing from A
in your original repository and squashing B
onto it:
git rebase -i `A`
# change "pick b" to "squash b"
You'll get a chance to change commit message at which point you could make it X
's.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With