Undo working copy modifications of one file in Git? Undo working copy modifications of one file in Git? git git

Undo working copy modifications of one file in Git?


You can use

git checkout -- file

You can do it without the -- (as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using -- is best.

You can also check out a particular version of a file:

git checkout v1.2.3 -- file         # tag v1.2.3git checkout stable -- file         # stable branchgit checkout origin/master -- file  # upstream mastergit checkout HEAD -- file           # the version from the most recent commitgit checkout HEAD^ -- file          # the version before the most recent commit


Just use

git checkout filename

This will replace filename with the latest version from the current branch.

WARNING: your changes will be discarded — no backup is kept.


git checkout <commit> <filename>

I used this today because I realized that my favicon had been overwritten a few commits ago when I upgrated to drupal 6.10, so I had to get it back. Here is what I did:

git checkout 088ecd favicon.ico