1

On my develop branch, i made a number of changes which didn't work out, so i went back by two commits, and then branched off and on my new branch made all the relevant changes, which now perform that task properly.

I want to make develop be what my new branch now is.

My thought is that i should somehow remove those two changes from the develop branch, and then merge back in. If this is the right way to do it, how can i do that? If it isn't, what should I do to solve this problem?

There isn't anybody else working on this project, so no worries of problems with that.

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
Andrew
  • 7,693
  • 11
  • 43
  • 81

2 Answers2

1

You should

$ git checkout develop

and then interactive rebase to delete the two trash commits:

$ git rebase -i HEAD~3

Remove the lines containing the commits you no longer want.

Then update develop with progress made on new-branch:

$ git rebase new-branch

And finally clean up:

$ git branch -d new-branch
jshawl
  • 3,315
  • 2
  • 22
  • 34
  • 1
    using `rebase` for this is probably something of a detour either way. The nice way, if the earlier commits have been published, is `revert`. If the old commits should be entirely removed, `reset --hard` (as explained more detail in [this answer](http://stackoverflow.com/a/1470452/1761499)) – Nevik Rehnel Dec 15 '13 at 08:56
0

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.

Bert F
  • 85,407
  • 12
  • 106
  • 123