How do you get a specific version from Git in Visual Studio 2015?

后端 未结 3 642
孤街浪徒
孤街浪徒 2020-12-25 09:43

Is there a way to get a specific version (from a specific commit) of a file in Visual Studio 2015 - Team Explorer/Team Services Git?

I simply wish to run the solutio

3条回答
  •  生来不讨喜
    2020-12-25 10:07

    (This works in both VS2015 and VS2017.)

    Note this question, and this answer, is for a single file (or small number of files). If you want to do this for many files, simply make a new branch from, or reset hard to, the desired commit like the other answers propose. But since checking out an old commit can take a lot of time, especially for large repos, I believe this is the simplest way for a single file:

    1. In Solution Explorer, open the current version of your file.
    2. Still in Solution Explorer, right click on the file and choose "View History".
    3. In the history window, find the commit for the version you want to test with. Right click on it and choose "Open". This pops up a temporary file with the contents of the desired version.
    4. Copy the contents of that version (Ctrl-A Ctrl-C) and paste it over the actual current version.

    Now you can do whatever you want to do with that file, and then undo the pending change when you're done.

提交回复
热议问题