5

I have committed to master branch mistakenly and unfortunately other devs have committed their changes on top of it. So I want to remove all of my commits. This is my commit list:

enter image description here

I want to delete all commits on 20 Aug 2016. What is your recommendation?

halfer
  • 19,824
  • 17
  • 99
  • 186
Hesam
  • 52,260
  • 74
  • 224
  • 365

1 Answers1

2
git rebase -i ca83eb3

When the interactive rebase happens, your text editor will come up. change pick to drop for the five commits you made. This will drop the commits from history after you save and exit the editor.

Of coarse we could do some bash with logging the sha with only commits from you on that day, but since it is only 5 commits, let's just do this easy rebase.

BUT:

You should not do this. Now that your commits are public, every developer’s code will have to be reset once you change history of their remote. Instead, consider leaving it, or making an additional commit that removes your code. You don't want to change history on public branches.

Community
  • 1
  • 1
Bryce Drew
  • 5,777
  • 1
  • 15
  • 27
  • You should warn the OP about the dangers of `git rebase`. Particularly since these changes exist on `master` and other developers have already committed on top of the problem commits. – Code-Apprentice Aug 22 '16 at 17:57
  • Thank you. I have edited the post accordingly. – Bryce Drew Aug 22 '16 at 18:00
  • 2
    You are right as this approach makes trouble for other devs. So I created a new branch and used `git revert ` and finally merged this branch. I suggest ti use this way to anyone who is working on a project that several devs are working on a same repo. more info: https://www.atlassian.com/git/tutorials/undoing-changes/git-revert – Hesam Aug 22 '16 at 20:27
  • You are entirely correct. That is the way to do it. (That command slipped my mind). – Bryce Drew Aug 22 '16 at 20:32