python-scripts/scripts/20_restore_file_from_git.py
2016-12-17 09:22:43 -07:00

14 lines
398 B
Python
Executable File

from subprocess import check_output, call
file_name = str(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.
"""