↑ ↓ select, Enter open, Esc close

Discard local changes to a file

Adjust the values, the command updates live
user@server
git restore wp-config.php

Overwrites the file in the working directory with the version from the index or the last commit. Useful when someone experimented directly with a versioned file on a server and the clean state should be restored. With . instead of a file name, all changes in the current directory are discarded.

Note: Uncommitted changes are gone for good afterwards, and even git reflog cannot help. Check with git diff first or save them with git stash.

Also searched as

  • git discard changes to file
  • revert file to last commit
  • git checkout file discard changes

Related one-liners

All in Git

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.