2021-01-05 17:14:50 +01:00
title = Restore a file from the past
cards = checkout checkout-from commit
2021-01-05 16:58:42 +01:00
[description]
2021-01-05 17:14:50 +01:00
Here's a similar problem: you really liked the essay from the very first commit, and want to have it back! Well, checkout can also restore things from older commits, Here's how:
2021-01-05 16:58:42 +01:00
2021-01-05 17:14:50 +01:00
git checkout [commit] [file]
2021-01-05 16:58:42 +01:00
[setup]
2021-01-05 17:14:50 +01:00
echo "good version" > essay
2021-01-05 16:58:42 +01:00
git add .
git commit -m "Initial commit"
2021-01-05 17:14:50 +01:00
echo "bad version" > essay
git commit -am "\"Improve\" essay"
2021-01-05 16:58:42 +01:00
[win]
2021-01-05 17:14:50 +01:00
# Get the first version of your essay, and make a new commit with it.
test "$(git show main:essay)" = "good version"