# Git for non-programmers 3

Last time we finished with a change only in the working tree, one which I don’t want to keep. It is possible to just manually revert your changes but it is much quicker to use git.

## Reverting changes in the working tree

In this instance we will use git checkout to ‘checkout’ the version of universe.py in the index like so:

git checkout -- universe.py

This can also be done with git restore:

git restore universe.py

We can also refer to a directory to checkout everything below that directory, for example, to checkout the whole tree from the root of your project:

git checkout -- .

$git status HEAD detached at 73ae532 Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: pi.py The above example shows that I have added a new file pi.py so that it is ready to be committed, as you can see we can ‘unstage’ the file with git restore: git restore --staged pi.py ## Reverting commits Generally commits should not be reverted if they have been shared as everyone else that has a copy of the commit would have to revert it as well but if a commit is just in your local copy it is possible to undo with git reset.$ git log
Date:   Fri Jul 31 13:52:59 2020 -0500

Add a module to print pi

commit 73ae5322e3073a20758f7d7c98b8b3955ec3a4ea
Date:   Sun Jul 14 17:07:47 2019 -0500

Initial commit
\$ git log
Date:   Sun Jul 14 17:07:47 2019 -0500

Initial commit

Here I use the alias HEAD^ to denote the commit prior to HEAD (for more on HEAD see the previous post) but any commit can be referenced as the new HEAD. This form of the command leaves the working tree in place but resets the index to the state of the selected commit. If you also want the working tree to be reset use