DarkMatterz
DarkMatterz

Reputation: 65

Rollback GIT on TFS

I am a noob to TFS and GIT and migrated an existing Lightswitch project to TFS. I started a new project in TFS with a GIT repo and loaded my project, but something corrupted nearly immediately on the master file after renaming a parent directory. I am trying to revert back to my initially loaded commit (which I can download the zip and confirmed it works as expected), but end up just adding some other commit changes that aren't getting me back to the original.

As a preface, when I clone to Visual Studio, I believe it pulls the most current sln unless I pull from a zip. But with the zip, I can't push commits (or at least I think). I realize now >:P I was an idiot and should have started branching immediately, but long story short, the first load to TFS didn't pull in the sln because I pulled from my local git to the remote server, so I had to create a new solution based off the loaded git history. All this after upgrading VS 2013 >> 2015 to match the 2015 TFS server.

enter image description here

I tried 'git revert bf4d79..26aa08' with the long id's from 'git log' but it just added the top two on Monday. I feel I am going in the wrong direction and am afraid I am going to kill my multi month project. Worst case I delete the project from TFS and start all over.

BTW, I am the only developer on this and own all admin permissions to it. If you haven't guessed, I am self taught from the business side, but have been developing for some years now.

Any help is obviously much appreciated, and I have learned some valuable lessons in all this. Thanks!

Here is a better picture of what I am having difficulty with.

enter image description here

enter image description here

**************Answered******************

Thanks Terje Sandstrøm! Worked like a charm.

git reset --hard 4358ca58

git push -f origin master

Also, figured out why the initial transfer from git to TFS didn't carry the sln file. The sln was saved outside the git tracked folder.

Learning from mistakes may be hard, but it definitely keeps you from repeating it.

enter image description here

Upvotes: 3

Views: 7774

Answers (1)

Terje Sandstrøm
Terje Sandstrøm

Reputation: 1991

Since you are the only developer on that git repo, you can rewrite the history of the remote repository, that is the one that you have on the TFS server.

First ensure you have Git installed on your machine, see under Team Explorer, Settings, section Git, if there is a Install 3rd part git extensions there, please do that.
Then: Go to command line, use the Action under.. say Changes hub, and choose Open Command Prompt.

Do a git reset as follows:

git reset --hard 4358ca58

This will move your master pointer and workspace back to the commit you marked above. (E.g. see Revert to a commit by a SHA hash in Git?)
Then force push this to the remote - note, do this ONLY when you're sure no one else is using your remote.

git push -f origin master

(E.g. See Force "git push" to overwrite remote files)

You now have your master back, the remote is in sync. And as you say yourself, now you can branch off and do your experiments.

Upvotes: 8

Related Questions