1

I have written a pull-to-refresh feature and committed to Github already. That feature with 1.3.0 and already released in a new product version. Now I fireguard out some code I have modified of this feature is not well optimized, so I want to undo it now. I am about to release 1.4.0 now, so there are nearly hundreds of commits after that commits.

After googling I find some answers about reverting previous commit. But my problem is how to revert the almost hundreds times previous commits.

I tried to compared the differences by diff tool via git plugin of Eclipse, but found without any result because I move the original file to another package.

I feel really confused about that, do I have to undo it line by line?


EDIT What I want to do is more like merging the long time ago commit to the latest commit. Because I added new features to my latest commit and I don`t mean to lose them, meanwhile, I want to revert back some feature as well.

Thanks for your help!

Logan Guo
  • 865
  • 4
  • 17
  • 35

2 Answers2

1

It might be easier to:

  • create a branch before those commits you want to revert,
  • git cherry-pick all the commits of your current branch you want to keep: that will replay them on top of your branch, which has none of the commits you want to avoid.

Remember, you can cherry-pick a range of commits.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for your reply, but I am new to git, and I don\`t know how to use `git cherry-pick` correctly. – Logan Guo Nov 29 '14 at 10:15
  • @LoganGuo that is why I mention the link http://stackoverflow.com/a/1994491/6309 in my answer. I would doing a backup of your repo first, then experimenting. – VonC Nov 29 '14 at 10:16
1

I would first create an ' undo branch' of the current branch and than do a git rebase -i HEAD~XXX. The undo branch is not necessary, but if something goes wrong you can just delete it.

git checkout -b undo
git rebase -i HEAD~100

Replace HEAD~100 with the number of commits you want to go back in history. Alternatively you can also use a specific commit.

git rebase -i <commitid>

This will open the rebase interactive editor. Just delete the commits that you don't want by removing the pick <commitid> line.

Also take a look at https://stackoverflow.com/a/27076194/974186 for details about rebase interactive.

If you removed the commits from your undo branch and everything looks fine you can just point the original branch to the new rewritten history.

git checkout originalBranch
git reset --hard undo

Now you can push the changes, but it might be necessary to do a forced push. Git will normally reject the remote branch update if it is not in line. Take care if you do a forced bush, since you overwrite the remote branch and commits done in the meanwhile gets lost.

Community
  • 1
  • 1
René Link
  • 48,224
  • 13
  • 108
  • 140