To complete Tobias's answer, git checkout HEAD -- <files> will restore files from the most recent commit even if changes were staged.

In what situation do you use that script?

People on stack overflow seem to have pretty polarized opinions about fiddling with timestamps… one of the answers has something close, but there might be a simpler way…

On 20 June 2016 at 22:40, Eliot Miranda <> wrote:
Hi git mavens,

    I've used a script called svnrevert in the svn version that reverts any changed file in its argument(s), which may be directories, /and/ sets the modification date to the date at which the file was last checked in. I'd like the same functionality in git.  Her'es the subversion version:

# Revert file(s) or all modified files in a directory
# and touch them back to the checkin date
for f in "$@"
if [ -d "$f" ]; then
$0 `svn st "$f" | grep "^M" | sed 's/^M *//'`
if svn revert "$f"; then
changed="`svn info \"$f\" | grep 'Last Changed Date:' | sed 's/ *(.*//'`"
touch -t "`date -j -f 'Last Changed Date: %Y-%m-%d %H:%M:%S %z' \"$changed\" '+%Y%m%d%H%M.%S'`" "$f"

best, Eliot

Damien Pollet
type less, do more [ | ]