4
Develop ------------------------>
             \NewBranch----> 

I keep accidently commiting files that should not be commited because they change during compile and we can't use ignore on them att the moment.

Is there a way with Visual Studios Team Explorer OR TortoiseGit to revert only a single file or several selected files back to the parent branch develop?

MrTux
  • 32,350
  • 30
  • 109
  • 146
Daarwin
  • 2,896
  • 7
  • 39
  • 69
  • [This question](https://stackoverflow.com/questions/1669917/git-tortoisegit-how-to-revert-a-single-file-to-a-previous-revision-and-then) adresses resetting to a previous commit via TortoiseGit. If you revert to the head of the parent branch, this sould have the effect you're looking for. – kowsky Oct 24 '17 at 08:01

2 Answers2

8
git checkout Develop -- theFileYouWantToRevert

Moreover, if the file is generated and could be changed during compiling, you should consider add them to the .gitignore file

armnotstrong
  • 8,605
  • 16
  • 65
  • 130
  • 2
    Op did not ask about command line: `...with Visual Studios Team Explorer OR Tortoise...`. Also, [...it would be better to include some context, explaining how it works and when to use it](https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers) instead of posting only code. – kowsky Oct 24 '17 at 06:59
  • This is not Done with the graphical interface is it? – Daarwin Oct 24 '17 at 07:23
  • 1
    I am pretty sure you can't do this with visual studio plugin since it provides only basic git functionality. Not sure about tortoise. But I would have to agree that the best way to do this sort of thing is probably with the git command line... – code_fodder Oct 24 '17 at 07:41
  • 2
    @ElpieKay: This is not an answer to ops question. Simple as that. – kowsky Oct 24 '17 at 07:56
  • 1
    @kowsky Then I must be using a false Visual Studio. My false Visual Studio has a button in Team Explorer to open the `cmd` window. Is it too hard for you or OP to click the button and then type this simple command to solve this problem? – ElpieKay Oct 24 '17 at 08:11
3

In order to restore a file to a previous version you have several options in TortoiseGit, all start from the Log Dialog.

  1. You select the revision where you accidently committed the files, go to the lower file list and open the context menu on the specific file(s). There you select "Revert to parent revision".

  2. You select the revision you want to restore the files from and then select "Repository Browser" on the context menu of the revision. Now you see all files at this revision and you can save or drag'n'drop them to your working tree. (You can also directly open the Repository Browser using the context menu of the Windows Explorer, you might need to hold the shift key to see the entry).

PS: You could mark those files as skip worktree to prevent them from committing.

MrTux
  • 32,350
  • 30
  • 109
  • 146
  • Thank you! Such a intuitive and smooth solution. Exactly what i was hoping for. Just a small follow up question: This 'skip worktree', its not the same thing as adding to ignore file? For some reason in this project we dont add this files to the ignore list. – Daarwin Oct 25 '17 at 06:35
  • Please comment before downvoting – MrTux Aug 03 '18 at 07:03