user1016265
user1016265

Reputation: 2397

how to cut wrong commit [git]

I'm trying to apply gitflow approach in our development process, theoretically I like it. But there is one point what is not covered anywhere...

Everyone pushing their results to develop branch. In plan, we have 10 issues which should be done and released to beta and then to production. 2 from 10 issues are not finally fixed, but partially it is already in develop branch, because developer thought he did it well, but after tests bugs are come again. And now decision we need not to wait while that 2 issues will be fixed and we need to make an upload, means make release branch and test it on beta.

In original gitflow article says:

The key moment to branch off a new release branch from develop is when develop (almost) reflects the desired state of the new release. At least all features that are targeted for the release-to-be-built must be merged in to develop at this point in time

But what to do if in develop branch history we can see couple not required merges ? Do I need cut them somehow ? or do anything else ?

Thanks.

Upvotes: 1

Views: 1201

Answers (1)

asm
asm

Reputation: 8898

The safest thing to do in a situation like this is to use git revert to reverse the commits. This will create a commit that exactly reverses the commit in question. So git revert 1234567 will create a new commit on your branch that reverses the commit with SHA id 1234567.

A few points about doing this:

  • After you do a git revert merging the branch again will not bring the changes from the reverted commits back, you must revert the revert commits. So in our example of git revert 1234567 suppose this created revert commit 09876. Now your developer has properly implemented his feature and you want to merge it in. To get the changes removed by the revert you must now git revert 09876 and then merge his updated branch.
  • To make things easier on yourself revert the commits in order from most recent to least recent. So if you have commits 1, 2, 3 where 1 is HEAD do git revert 1, git revert 2, git revert 3. Then if these reverts create commits 8, 9, 10 to reintroduce the changes revert them in order most to least recent.
  • It's also possible to revert merge commits but that's a bit more complicated, it's described in the man page, git help revert
  • If you need to do this you should read this article by Linus, he describes many of the things you need to think about.

Upvotes: 2

Related Questions