0

I accidentally make a code commit to a Visual Studio Online (TFS) repository that I do not want someone to get the latest on. I want to remove it as if it never existed. Should I be doing a rollback or is there a better way?

I basically want to delete the latest commit. But not sure if rollback will do this for me.

Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
  • I think this question boils down to removing the last commit on a remote git repository, so I think this [Stack Overflow post](https://stackoverflow.com/questions/8225125/remove-last-commit-from-remote-git-repository) will do the trick. – Jacob Maki Jun 13 '17 at 16:14

1 Answers1

1

If you're using Git, you can use git reset to move your branch back to the commit prior to the commit that contained the unwanted file, then force push the branch. Beware that force pushing is potentially dangerous. Be sure you understand the implications prior to using it.

You can also use git revert to create a commit that undoes the change, but the commit containing the change will still be present.

If you're using TFVC, you can use tf.exe with the destroy parameter to delete the file: https://www.visualstudio.com/en-us/docs/tfvc/destroy-command-team-foundation-version-control

Note that destroy removes files, not commits. Rollback is your best bet in the event that you want to retain the file and its history, but revert the content to how it was at an earlier point.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120