-1
➜  amfrost_crm git:(master) gst
On branch master
Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

nothing to commit, working directory clean

These five commits are bad and I want to remove them permanently from local and remote and rebase HEAD to the good working commits.

iBug
  • 35,554
  • 7
  • 89
  • 134
gaurav singh
  • 69
  • 1
  • 2
  • 5

1 Answers1

0

What you want to do is discard part of the work previously made and already pushed to the remote. This means modifying repository history, and it's almost always a bad idea, for at least two reason:

  1. You are discarding work already done, and may not be able to recovery it. Even if it was wrong you can still keep track of it and simply go ahead with a new commit that discard the differences.
  2. If someone else apart you is working on the repository he will no longer be able to push to it, since the history of the remote and their local won't match. They will have to clone again the repository and add their work manually, merging with diff tools.

If you really want to change the history of the remote repository, matching it with your local repository, you can simply do a force push:

git push --force

Anyway, as others already pointed out in the comments this might be a really bad idea.

ErniBrown
  • 1,283
  • 12
  • 25
  • 2
    He can do this **provided he is not part of a team** and **he doesn't have any other branches based on these 5 commits**. This should be verified **before** `git push -f` (advice) is given. – Lasse V. Karlsen Aug 28 '18 at 10:16
  • @LasseVågsætherKarlsen "Not part of a team" means it's OK do this in personal repositories? – iBug Aug 28 '18 at 10:21
  • 1
    It *might* be, it depends, but we should make sure this won't cause bigger problems for the OP before advicing using this command. If you're part of a team, **talk with your team first**, otherwise you risk removing work they've done or just getting those bad commits back upon the first push by someone else. Personal repositories means you're in control, though you may still not know the ramifications of this command. – Lasse V. Karlsen Aug 28 '18 at 10:25
  • @LasseVågsætherKarlsen You are right, my note about the risks was not clear, so I edited the answer – ErniBrown Aug 28 '18 at 10:41