← Useful Tips
GitGit

git restore file.py: Discard local changes in a specific Git file

Use git restore on a file when you intentionally want to discard its uncommitted local changes. Check git diff first if the changes matter.

git restore file.py
CautionThis action can change data or working state. Check what it will do before you run it.

Why it helps

Use git restore on a file when you intentionally want to discard its uncommitted local changes. Check git diff first if the changes matter.

How to use it

  1. Open the relevant app or terminal.
  2. Use the shortcut or command above in the relevant context.
  3. Check the result; for commands that change data, test on a small example first.
People also search for
git restore file.py: Discard local changes in a specific Git filegit restore file.pydiscard local changes in a specific git filehow to discard local changes in a specific git fileGit discard local changes in a specific git file

Related tips