restore file from git

This commit is contained in:
Michael Herman 2014-11-11 20:43:23 -07:00
parent 5631b3cc4c
commit 9f035a609e
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,13 @@
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.
"""

View File

@ -18,3 +18,5 @@
1. **16_jinja_quick_load.py**: Render a quick Jinja2 template 1. **16_jinja_quick_load.py**: Render a quick Jinja2 template
1. **17_rewrite_git_history.md**: Backdating/Rewriting Git history (use at your own risk) 1. **17_rewrite_git_history.md**: Backdating/Rewriting Git history (use at your own risk)
1. **18_zipper.py**: Zip contents of a directory, adding a timestamp to the filename 1. **18_zipper.py**: Zip contents of a directory, adding a timestamp to the filename
1. **19_tsv-to-csv.py**: Convert TSV to CSV
1. **20_restore_file_from_git.py**: Restore file from Git History