diff --git a/README.md b/README.md index f75f4fb..84cb57d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1645 TILs and counting..._ +_1646 TILs and counting..._ See some of the other learning resources I work on: - [Get Started with Vimium](https://egghead.io/courses/get-started-with-vimium~3t5f7) @@ -385,6 +385,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Renaming A Branch](git/renaming-a-branch.md) - [Resetting A Reset](git/resetting-a-reset.md) - [Resolve A Merge Conflict From Stash Pop](git/resolve-a-merge-conflict-from-stash-pop.md) +- [Restore File From One Branch To The Current](git/restore-file-from-one-branch-to-the-current.md) - [Review Commits From Before A Certain Date](git/review-commits-from-before-a-certain-date.md) - [Run A Git Command From Outside The Repo](git/run-a-git-command-from-outside-the-repo.md) - [Set A Custom Pager For A Specific Command](git/set-a-custom-pager-for-a-specific-command.md) diff --git a/git/restore-file-from-one-branch-to-the-current.md b/git/restore-file-from-one-branch-to-the-current.md new file mode 100644 index 0000000..d658b3d --- /dev/null +++ b/git/restore-file-from-one-branch-to-the-current.md @@ -0,0 +1,20 @@ +# Restore File From One Branch To The Current + +On one feature branch I have created some files and made changes to some +existing files as part of spiking a feature. Now I'm on a different branch +taking another shot at it. I want changes from one or two of the files. In the +past I've used `git-checkout` for this task. However, I believe this is one of +the use cases they had in mind when they added `git-restore`. + +What I want to do is _restore_ the state of a file as it appears on some source +branch to my current branch. Here is what that looks like: + +```bash +$ git restore --source=some-feature-branch app/models/contact.rb +``` + +Now when I check `git status` I'll see the state of that file on the +`some-feature-branch` branch overlayed on my current working copy. If the file +doesn't exist, it will be created. + +See `man git-restore` for more details.