Discard unstaged changes in git

For a specific file use:

$ git checkout path/to/file/to/revert

For all unstaged files use:

$ git checkout -- .

Don’t forget to add ‘.’ at the end.


List all the files in a git repository

If you want to list all files for a specific branch, e.g. master:

$ git ls-tree -r master --name-only

-d Show only the named tree entry itself, not its children.
-r Recurse into sub-trees.

You can specify HEAD instead of master to get the list for any other branch you might be in.

If you want to get a list of all files that ever existed:

$ git log --pretty=format: --name-only --diff-filter=A | sort -