-1

I already found answers about revert what will make a new commit, that didn't work for me (maybe I need clearer explanation) but then I found out that this will not delete the commits themselves/the history (what I want to do). Then I had a idea which might work:

  1. make a branch at commit 3 (remember I just want to delete first and second commit)
  2. make that branch master
  3. delete the branch with the 2 commits I want to delete

Don't know if that can work or not. But I hope you can help me

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Sain Linkerty
  • 63
  • 2
  • 13

1 Answers1

0

You can do several things:

  1. If you pushed your branch and your "server" configured to block non fast forward commits you cant actually remove the deleted commits you will have to use revert as you mentioned in your question.
  2. If you can push you can perform a push -f which will "force" the push and will remove your commits from the history.

How to remove unwanted commits:

  1. git reflog will display a list of your git history, checkout to the desired commit (like you said 3 commits back), create branch and push it (with the -f flag). It will remove the unwanted commits.
  2. In case you cant push it (read why above) you can revert the commits and remove the unwanted code and then push the new "removed" code.
Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167