python-scripts/20_restore_file_from_git.py
2015-10-15 22:51:07 +01: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.
"""