Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git exclude a commit in a branch

Tags:

git

revert

commit

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!

like image 868
lprsd Avatar asked Mar 25 '10 22:03

lprsd


1 Answers

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.

like image 170
crazyscot Avatar answered Oct 05 '22 16:10

crazyscot