14

I have a commit, I have stored in a branch, because this should go only to a specific box.

I have merged it to the branch master, but not the branch dev, that I use locally.

Now, by mistake I merged master to dev and that introduced this commit to dev.

I know can git revert sha, to branch dev; but since this is going to introduce a commit that undoes that commit (I am guessing, I haven't exactly tried this), when I merge master, will this commit be undone too?

If so, how do I undo this commit only from the branch dev.

And oh, git reset HEAD^1 --hard is not an option because there are other commits on master, after the un-needed commit.

If reset back again and apply is the only option, then how do I only merge those extra commits from master other than the un-needed commit.

Update:

Here is the commit tree. Looks complex. I have pointed to the commit, that I don't need in the dev. (I have also removed any personally identifiable information, thanks for understanding. It is so much simpler to screenshot gitk than to ascii art.) alt text

Thanks in advance!

4

2 に答える 2

20

On a scratch copy of your branch, git rebase --interactive and drop the unwanted commit. Alternatively, you could create a new branch upstream of the unwanted commit and git cherry-pick the desired commits onto it.

There are probably more ways to achieve this.

于 2010-03-25T22:53:28.997 に答える
2

git reflog, then git reset --hard are your friends to undo mistakes.

In order to avoid a single commit when merging a branch, this is what I have just used in my project:

  • Assume: merge from branch B to head.
  • Identify revid of commit to be avoided (R0)
  • Identify revid of commit just prior to R0 (R1)

    git merge <R1>
    git merge -s ours R0
    git merge B
    
于 2010-12-20T15:55:49.320 に答える