-3

I learned git a while back and I have forgot the methods that are used the least. I have an emergency, I have homework due tomorrow and I should be writing the code rather than messing with git. I have been researching this and I just don't have the time to mess around with this any more.

I've looked at this answer but its too much information, I get lost in the noise How to revert Git repository to a previous commit?

so look here is what I am looking for. I want to rewrite history completely in the local and remote repos. I need to go to a specific commit and make it look like that is the latest commit ever made. To say it in another way. If the professor committed something on the 4th and I made changes on the 5th 6th and 7th, I want to delete those changes completely. To where the last commit ever made was on the 4th. I promise to rewatch and re study git this weekend but right now guys I need a solid, straight answer please.

Community
  • 1
  • 1
  • 1
    Which part of `git checkout ` doesn't work for your needs? Which part of [the accepted answer](http://stackoverflow.com/a/4114122/139010) is not sufficiently clear? – Matt Ball Feb 02 '16 at 00:15
  • If the remote repo was been fetched by someone else, you'll just break the repo for them. – Microfed Feb 02 '16 at 00:17
  • this. "This can be used to view an old state of your project without altering your current state in any way. Checking out a file lets you see an old version of that particular file, leaving the rest of your working directory untouched." Its confusing does it do what I want or not? I honestly have no idea it looks like it just allows me to view the old commit then thats it – Christopher Jakob Feb 02 '16 at 00:18
  • I understand that @Microfed but that doesn't matter as it wasn't fetched by anyone else. So I just need the answer as I have accounted for that already, please. – Christopher Jakob Feb 02 '16 at 00:18
  • Then, you just need to get the `sha` of the commit made by your professor, then do `git reset --hard` and `git push -f` to rewrite history on the server – Microfed Feb 02 '16 at 00:22
  • http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html – Microfed Feb 02 '16 at 00:23
  • Ok, thank you Microfed. I thought that might be the answer. Heres the thing sometimes people add so much noise to answers. Which is actually not noise its good information but when your stressed out and need an answer now, like i do and have been spending the last 2 hours trying to find one its not a luxury to have. – Christopher Jakob Feb 02 '16 at 00:24
  • 1
    Possible duplicate of [Revert Git repo to a previous commit](http://stackoverflow.com/questions/4114095/revert-git-repo-to-a-previous-commit) – Andrew C Feb 02 '16 at 00:45

1 Answers1

1

Assuming you want the commit C to be the last commit, do the following:

  1. git reset --hard C
  2. git push -f

That's all you need to do.

David Deutsch
  • 17,443
  • 4
  • 47
  • 54