Skip to content

Commit 9f035a6

Browse files
committed
restore file from git
1 parent 5631b3c commit 9f035a6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

20_restore_file_from_git.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from subprocess import check_output, call
2+
3+
4+
file_name = str(raw_input('Enter the file name: '))
5+
commit = check_output(["git", "rev-list", "-n", "1", "HEAD", "--", file_name])
6+
print str(commit).rstrip()
7+
call(["git", "checkout", str(commit).rstrip()+"~1", file_name])
8+
9+
10+
"""
11+
After entering a filename, this script searches your Git history for that file.
12+
If the file exists, then it will restore it.
13+
"""

readme.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
1. **15_check_my_environment.py**: Pass in a config file based on your environment.
1818
1. **16_jinja_quick_load.py**: Render a quick Jinja2 template
1919
1. **17_rewrite_git_history.md**: Backdating/Rewriting Git history (use at your own risk)
20-
1. **18_zipper.py**: Zip contents of a directory, adding a timestamp to the filename
20+
1. **18_zipper.py**: Zip contents of a directory, adding a timestamp to the filename
21+
1. **19_tsv-to-csv.py**: Convert TSV to CSV
22+
1. **20_restore_file_from_git.py**: Restore file from Git History

0 commit comments

Comments
 (0)