-1

Current Commit History

    O- commit C  HEAD
    |
    O- commit B 
    |
    O- commit A  ← I want to delete this commit
   /
  /  branch: feature/foo
 /
0 -- master HEAD

Goal Commit History

    O- commit C  HEAD
    |
    O- commit B 
   /
  /  branch: feature/foo
 /
0 -- master HEAD

How do I do that?

DarkTrick
  • 2,447
  • 1
  • 21
  • 39

1 Answers1

-1

You need to use git rebase --interactive:

  • git rebase --interactive HEAD~3
  • This will bring up an editor containing something like this:
pick aaaaaaaa commit A
pick aaaaaaaa commit B
pick cccccccc commit C
  • This show the last 3 commits (hence HEAD*~3*)
  • remove the first line, so it it looks like this:
pick aaaaaaaa commit B
pick cccccccc commit C
  • This tells git to use only commit B and C in from the history
  • Save your changes
  • Close editor

Difficulty

Experience with git rebase [branch name] ( For the worst case scenario )

Worst case

Case: The commit you removed was not independent of the other commits. And now git rebase wants stuff from you, you have no idea about. Solution: Reverse the process with git rebase --abort

DarkTrick
  • 2,447
  • 1
  • 21
  • 39