diff --git a/snippets/copy-file-from-branch.md b/snippets/copy-file-from-branch.md new file mode 100644 index 000000000..a929d29cf --- /dev/null +++ b/snippets/copy-file-from-branch.md @@ -0,0 +1,18 @@ +--- +title: Copy a file from another branch +tags: branch,intermediate +--- + +Copies a file from another branch to the current branch. + +- Use `git checkout ` to copy the specified `` from the specified ``. + +```sh +git checkout +``` + +```sh +git checkout patch-2 +git checkout patch-1 "30seconds.txt" +# `patch-2` branch now contains the 30seconds.txt file from `patch-1` +``` diff --git a/snippets/restore-deleted-file.md b/snippets/restore-deleted-file.md new file mode 100644 index 000000000..bc256d62d --- /dev/null +++ b/snippets/restore-deleted-file.md @@ -0,0 +1,18 @@ +--- +title: Restore a deleted file +tags: branch,intermediate +--- + +Restores a file deleted in a specific commit. + +- Use `git checkout ^ -- ` to restore the specified `` deleted in the specified ``. + +```sh +git checkout ^ -- +``` + +```sh +# "30seconds.txt" was deleted in the commit `3050fc0de` +git checkout 3050fc0de^ -- "30seconds.txt" +# Restores the 30seconds.txt file +```