-2

I am in the process of learning git.

I have the following commit on a branch

commit 3

commit 2

commit 1

commit 0

how can I remove commit 1 but keep commit 2 and 3 on a remote branch?

  • Just use git revert. It will add a new commit to the top (commit 4 I guess) that reverts what commit 1 did. Git never ever removes history, only adds. – Chris Eberle Sep 20 '13 at 00:41

1 Answers1

2

Two possible, different solutions:

  1. git revert commit1; git push - creates a new commit, which reverts commit 1

  2. git rebase -i HEAD~3 then just delete the commit 1 and git push -f but note this requires privilege to "force push" which means rewriting history which is not always desirable (do your research, this is typically viable only when working on code that has not been distributed/published/frozen). Refer to man pages for more details.

Jan Matějka
  • 1,880
  • 1
  • 14
  • 31
  • 2
    You should make it clear that 1 and 2 aren't meant to be used together, they're both mutually exclusive solutions to the problem. –  Sep 20 '13 at 04:48