0

I'm learning git and I have a problem. I created a new repository on Bitbucket and I have 3 commits:

  • commit A - v1.0.2

  • commit B - v1.1.1

  • commit C - v1.0.0

How to update "commit B" - files (removed, edit etc.)? How to delete commits A and B (on Bitbucket)?

  • git rebase
  • git revert
  • git reset?
Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126
Michael
  • 131
  • 1
  • 6

1 Answers1

0

You can use interactive rebase:

$ git rebase -i HEAD~3

This will rebase last 3 commits. It opens approximatelly the following in your text editor:

pick 1111111 commit C - v1.0.0
pick 2222222 commit B - v1.1.1
pick 3333333 commit A - v1.0.2

It gives you opportunity to change your commits in some way. In your particular case, you want to change pick on line with commit B to edit and remove lines with commits A and C. After saving and exitting the editor, it prompts you to recommit changes that were made in commit B and delete commits A and C.

This however changes the history in your branch, so you'll have to force push to it. Be extra careful with this if you are collaborating with someone else!

Ondrej Slinták
  • 31,386
  • 20
  • 94
  • 126