0

Currently, in one of my branch, I have two commits commit old and commit latest. commit latest was done after the commit old. Now, I want to merge only commit latest to the master. I don't want any changes the commit old will do. How can I remove a particular selected commit from github? After reading other answers, I found that I cannot do directly from github. I need to first revert back the changes on my local branch and then make a push again? Its confusing me how can I only revert changes of a particular commit and still keep the changes of my latest commit and if I do that what I need to do after it?

I would really appreciate any help or link. I am new to git/github.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124
  • http://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github – varun May 30 '13 at 20:46
  • I did read this thread before but could understand it. Then I follwed http://wiki.sniping.org/drcs/git/tricks link and now I understand what the person was trying to do. Thanks anyways. :). In the above link the person shows by an example. – Shobhit Puri May 30 '13 at 20:57
  • To the given solution the ink you gave, I added `--interactive`. So I did `git rebase --interactive HEAD~3`. This `interactive thing made it very easier. So just deleting a row from there and force pushing it to the branch did the trick. – Shobhit Puri May 30 '13 at 21:07

2 Answers2

1

You can push just commit latest (assumes master local branch at commit latest and is based on origin/master) by:

git checkout -b tmpbranch HEAD~2
git cherry-pick master
git push origin tmpbranch:master

One of the best features of git is that there are some many ways to revise local history, before the final push. What I just listed is just one way.

cforbish
  • 8,567
  • 3
  • 28
  • 32
0

In git if you have a commit - its whole history is part of it. Therefore you cannot merge a single commit, as this implies you merge its whole history, too.

If you do not want the changes of a single commit in the past, the trick is adding another commit on top of the latest one, which is undoing whatever the unwanted commit did. - This can be done with git revert.

There is also git rebase which is very powerful. But please do not use it until you completely understood how git works. - Otherwise you can break things much too easily.

michas
  • 25,361
  • 15
  • 76
  • 121