randombits
randombits

Reputation: 48490

Git merge a commit that I already pushed to a remote origin

I just made a commit on my git repository and sent it up to remote origin. There was of course a syntax error in the commit I made. What's the best way to fix the syntax error locally, and then merge it with my last commit so that people reading remote commits don't have to look at two commits but instead see one/clean commit?

Upvotes: 0

Views: 36

Answers (1)

Chowlett
Chowlett

Reputation: 46677

Don't. People upstream may have already pulled your commit, and you're looking for a way to rewrite history so it looks like you never made it. That will confuse their client.

That said, if you're sure no-one will have pulled yet, or you can inform everyone that has what you're doing, you can do this:

  1. Fix your error locally
  2. git add your fixed files
  3. git commit --amend to include your fixes in the previous commit
  4. git push -f to forcibly overwrite the remote's history.

Anyone who has pulled since your broken push will need to git pull -f to overwrite at their client.

Upvotes: 1

Related Questions