How to revert a file to the last committed state
Using git checkout to undo changes to your file
Git has many useful functions. One of my favourites is to scrap the work ive just done on the file I currently working on ( because I’ve gone down the wrong path or screwed it up) and start again from the files last committed state.
Functions like this give me peace of mind as a developer. If I screw up my file I can easily revert it.
Revert a file to the last committed state
1
git checkout pathtofile/filename.ext
Revert a file to the last committed state using fugitive
Fugitive is a vim plugin that integrates Git into the vim code editor. It’s super handy as you don’t need to change windows to do git functions like reverting changes to a file.
open the file in vim
1
git checkout .
This post is licensed under
CC BY 4.0
by the author.