I just encountered the following scenario:
Some commits in a branch [develop] (multiple people working on it) were causing issues and I wanted to copy them to a separate branch [feature1] so they could be fixed/added to (and the code removed from the current branch [develop]). They had already been pushed to remote [origin/develop] quite a while ago.
What I ended up doing was: 1. creating a separate branch [feature1] 2. deleting the code from the [develop] branch
I then realised that if someone else did a git merge [develop] (to bring in any new desired changes) whilst on [feature1], the deletions would get pulled through (and they would lose the code). But I needed to keep these historical commits. I then therefore thought I could:
- merge in the deletion: git merge [develop] (whilst on [feature1])
- cherry-pick the hash of the old commits I wanted to keep.
I then realised I could not do that (it was saying my local changes would get overwritten, even though there were no local changes). I presume this is because the old commits were dated as older than the deletion I had just merged in.
There must be way of doing this, kind of like a cherry-pick force or something else! Any ideas what the best command would be for this scenario?
Thanks