0

I am using git and there were some files pushed by another user over a space of a few commits, which should not have been pushed yet. They are the most recent commits, and I can see in git log the last good commit that I would like to reset my local system to, and then push all local changes back so that the system is in a clean state again

How do I do this? We are using a repo on github, if it makes any difference.

The intent afterwards is for that user to then do a pull, resolve conflicts locally, and henceforth be advised against pushing stuff that isn't ready to be pushed yet. But of course, I need to get the cloud repo back to a good state first.

markt1964
  • 2,638
  • 2
  • 22
  • 54
  • possible duplicate of [How do you roll back (reset) a git repository to a particular commit?](http://stackoverflow.com/questions/1616957/how-do-you-roll-back-reset-a-git-repository-to-a-particular-commit) – jthill May 21 '14 at 06:37
  • Duplicate of [Revert to previous Git commit](http://stackoverflow.com/questions/4114095/revert-to-previous-git-commit) –  May 24 '14 at 23:00

1 Answers1

1

The question "How do you roll back (reset) a git repository to a particular commit?" is about using git reset --hard to revert to a good commit.

But, "to get the cloud repo back to a good state", that will leave you with the only option of a git push --force, which can be inconvenient for other users accessing that same cloud repo: they will need to reset their own branch to the new (fetched) origin/master branch.

If you don't mind leaving those bad commits in the history, you could use git revert in order to make one more commit (which would cancel said bad commits), and push (regular push) that extra commit.

You can revert multiple commit that way, with git revert or a combination of git reset --hard and git reset --soft.

Everyone accessing the remote repo would do a regular git pull, and see any modification introduced by the bad commits disappear.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The problem I have with doing a git reset --hard is that when I push this, it rewrites the history of the repository. I don't mind leaving the bad commits in the history, but I want the files to be restored to what they were previously. The documentation on 'git revert' is unclear how I would use it to roll back changes from several commits, some of which could have been merges. – markt1964 May 21 '14 at 17:55
  • @markt1964 then I would recommend the reset --hard + reset --soft approach: very easy to do (at the end of http://stackoverflow.com/a/1470452/6309). – VonC May 21 '14 at 18:52