1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00

Add Unstage Changes With Git Restore as a git til

This commit is contained in:
jbranchaud
2021-01-22 13:27:41 -06:00
parent fe8a512fa8
commit 9a9a68e1e5
2 changed files with 32 additions and 1 deletions

View File

@@ -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)

View File

@@ -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 <file>..." to unstage)
See `man git-restore` for more details.