Reverting files in Git can be confusing because there are multiple ways to accomplish it. Let’s go over some basic commands to help you undo your work effectively.

If you want to revert a single file back to its last committed state, use:

git checkout

However, if you have a file and a branch with the same name, you’ll need to specify that you mean the file to avoid ambiguity:

git checkout --

If you need to discard all changes in your working directory, you have two main options:

git checkout -f

or

git reset --hard

Be cautious with these commands, as they will permanently delete all uncommitted changes in your directory.

It’s important to note that git revert is not the same as svn revert. git revert is used to create a new commit that undoes the changes of a previous commit. This command is useful for reversing specific commits and will be covered in more detail in another tip.