Rather than thinking of it as 'removing commits', think of git as a tree/paths of commits and a git branch as a label that you can move along the branches/paths. When you git commit
you are "growing" the tree and moving the git branch label further along the path. You can visualize this using gitx or git log --oneline --abbrev-commit --all --graph --decorate
liberally.
You can think of what you want to do as moving develop
back 2 commits (reset
) to the "fork" in the road where you branched off the new commits and then moving develop
down a different path of commits (merge --ff-only
):
$ git status # make sure you don't have an uncommitted changes
$ git checkout develop
$ git tag save # bookmark just in case
$ git branch bad-branch # alternate way to save a bookmark
$ # move develop back two commits, presumably back to where you branched off
$ git reset --hard HEAD^^
$ # move develop down the other branch of commits (marked by new-branch)
$ git merge --ff-only <new-branch>
You should refresh gitx or run the git log
command after every command to help you visually what's happening.
The --ff-only
option is just a safety to make sure you are just moving the branch label around, not actually merging to branches (paths) together.