From 9a9a68e1e5914e34c1f2abc85c8a10cac82b3ee7 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Fri, 22 Jan 2021 13:27:41 -0600 Subject: [PATCH] Add Unstage Changes With Git Restore as a git til --- README.md | 3 ++- git/unstage-changes-with-git-restore.md | 30 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 git/unstage-changes-with-git-restore.md diff --git a/README.md b/README.md index 4323857..4023f9a 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://tinyletter.com/jbranchaud). -_1019 TILs and counting..._ +_1020 TILs and counting..._ --- @@ -279,6 +279,7 @@ _1019 TILs and counting..._ - [Stashing Untracked Files](git/stashing-untracked-files.md) - [Switch To A Recent Branch With FZF](git/switch-to-a-recent-branch-with-fzf.md) - [Two Kinds Of Dotted Range Notation](git/two-kinds-of-dotted-range-notation.md) +- [Unstage Changes Wih Git Restore](git/unstage-changes-with-git-restore.md) - [Untrack A Directory Of Files Without Deleting](git/untrack-a-directory-of-files-without-deleting.md) - [Untrack A File Without Deleting It](git/untrack-a-file-without-deleting-it.md) - [Update The URL Of A Remote](git/update-the-url-of-a-remote.md) diff --git a/git/unstage-changes-with-git-restore.md b/git/unstage-changes-with-git-restore.md new file mode 100644 index 0000000..79ff7ae --- /dev/null +++ b/git/unstage-changes-with-git-restore.md @@ -0,0 +1,30 @@ +# Unstage Changes With Git Restore + +Git 2.23 introduced the `restore` command which is a more direct alternative to +`checkout` and `reset` for restoring the state of the working tree and the +index (staging area). + +With the `--staged` flag, we can unstage changes, moving them from the index to +the working tree. + +> To restore a file in the index to match the version in HEAD (this is the same +> as using git-reset(1)) + +``` +$ git restore --staged README.md +``` + +Staged changes to `README.md` will be removed from the index and put on the +working tree. + +``` +$ git restore --staged . +``` + +That will unstage all changes on the index. + +This is now recommended by Git when you run `git status`: + +> (use "git restore --staged ..." to unstage) + +See `man git-restore` for more details.