1

Someone in my team has accidentally pushed a commit to GIT that no one should pull (since it contains many changes and basically breaks everything we have).

He tried to revert to another revision, but was given an error.

So basically, he has been working on his local copy for the whole day. No one has either pushed or pulled from the repository.

What we want to do is somehow keep his local changes, but remove what he pushed.

How can we go about doing this?

Thank you.

Feytality
  • 245
  • 2
  • 4
  • 14

2 Answers2

0

git push --force will force your local branch to be pushed, even though there are new commits on the remote repository.

Sergiu Dumitriu
  • 11,455
  • 3
  • 39
  • 62
0

You're going to either want to reset the local git repo to a pre-push state and push that to the remote origin, or if you have access to your git server just revert it directly.

Local machine:

1. git log
   get the commit id for the last usable commit
2. git reset --hard <commit id>
   replace <commit id> with the id you retrieved in step 1
3. git push -f origin <branch name>

On git server:

1. git log
   get the commit id for the last usable commit
2. git reset --hard <commit id>
   replace <commit id> with the id you retrieved in step 1

Once the bad commit is gone just push the new changes like normal.

This is a common problem. Fixes have been posted for this type of thing before. Be sure to search before asking, might save yourself some time!

Community
  • 1
  • 1
SuperFamousGuy
  • 1,455
  • 11
  • 16