1

I'm getting a little confused with git branch management and could use a little help. I know there are several question on SO that are related, but I'm not sure if this situation is entirely the same and I don't want to mess things up.

We have a branch called 'master' that is meant to be a representation of what is currently in production. We have another branch called 'development' that represents what is on our test server and contains any current development/bug fixes that are ready for testing. When working on user stories or bug fixes, our developers are supposed to create a branch for each story/fix. When it is ready for testing, it is merged into development branch and the test server is updated. When story/fix is moved to production, it is merged into the master branch.

One of our developers recently pushed 8 changes directly into the master branch. These changes have since been merged from master into the development branch.

What I need to know is:

  1. How do I remove those commits from the master branch so master remains an image of what is actually in production. I've seen a number of SO posts advocating rebase or cherry-pick but I am uncertain if they apply and would appreciate specific advice for my situation.
  2. Is it safe to do this given the merge to development branch, i.e. will removing them from the master, however that is done, also remove them from the development branch? I'm confused because I see that after the merge they retain the same id and parent so I'm uncertain what effect deleting them from master will have, if any.

EDIT: I should also mention that I've seen this post which may be what I need, but again would appreciate confirmation and I'm still unsure how this would affect the merge to the development branch.

FYI, I'm using tortoisegit (but don't have to).

Thanks for any advice.

Community
  • 1
  • 1
K. Meke
  • 433
  • 2
  • 14

1 Answers1

1

The best thing to do is to revert the range of 8 commits with git revert c1..c2, where c1 and c2 represent the first and last commits you want to revert, respectively. This will undo the effects of those commits, without removing the commits themselves. That way, your merge into the develop branch is still valid.

Note that with this method, you will have 8 more commits in your master history, one for each reversion. If instead you want to have just one commit that undoes all 8 at once, and there have been no "legit" commits since the 8, then do the following:

git checkout -b temp-branch <SHA of last good commit>
git reset --soft master
git commit -m "Undoing 8 commits"
git checkout master
git merge temp-branch
git branch -d temp-branch

EDIT: changed 'goof' to 'good'!

K. Meke
  • 433
  • 2
  • 14
David Deutsch
  • 17,443
  • 4
  • 47
  • 54