python-scripts/20_restore_file_from_git.py
2014-11-11 20:43:23 -07:00

14 lines
401 B
Python

from subprocess import check_output, call
file_name = str(raw_input('Enter the file name: '))
commit = check_output(["git", "rev-list", "-n", "1", "HEAD", "--", file_name])
print str(commit).rstrip()
call(["git", "checkout", str(commit).rstrip()+"~1", file_name])
"""
After entering a filename, this script searches your Git history for that file.
If the file exists, then it will restore it.
"""