python-scripts/20_restore_file_from_git.py

14 lines
398 B
Python
Raw Normal View History

2014-11-12 04:43:23 +01:00
from subprocess import check_output, call
file_name = str(input('Enter the file name: '))
2014-11-12 04:43:23 +01:00
commit = check_output(["git", "rev-list", "-n", "1", "HEAD", "--", file_name])
print(str(commit).rstrip())
2014-11-12 04:43:23 +01:00
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.
"""