Reputation: 87225
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.)
Thanks in advance!
Upvotes: 14
Views: 15969
Reputation: 31
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:
Identify revid of commit just prior to R0 (R1)
git merge <R1>
git merge -s ours R0
git merge B
Upvotes: 2
Reputation: 12019
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.
Upvotes: 22