Skip to content

Recommend Use of git restore When Working With Files - #2187

Open
vermiceli wants to merge 2 commits into
git:gh-pagesfrom
vermiceli:patch-1
Open

Recommend Use of git restore When Working With Files#2187
vermiceli wants to merge 2 commits into
git:gh-pagesfrom
vermiceli:patch-1

Conversation

@vermiceli

@vermiceli vermiceli commented Jul 24, 2026

Copy link
Copy Markdown

Provides alternative examples using git restore for git reset commands that deal with restoring files from the worktree or index.

I believe this better aligns with the documentation, in particular Reset, restore and revert

git-restore[1] is about restoring files in the working tree from either the index or another commit. This command does not update your branch. The command can also be used to restore files in the index from another commit.

git-reset[1] is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.

Replaces `git reset` commands that deal with restoring files from the working tree or index with `git restore`.

I believe this better aligns with the documentation, in particular [Reset, restore and revert](https://git-scm.com/docs/git#_reset_restore_and_revert)

> git-restore[1] is about restoring files in the working tree from either the index or another commit. This command does not update your branch. The command can also be used to restore files in the index from another commit.
> git-reset[1] is about updating your branch, moving the tip in order to add or remove commits from the branch. This operation changes the commit history.
@vermiceli vermiceli changed the title Update git commands for unstaging changes Recommend Use of git restore When Working With Files Jul 24, 2026
@dscho
dscho requested a review from jvns July 28, 2026 12:54
@jvns

jvns commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I think this would be a good use of the "OR", like with "Delete unstaged changes to one file:" where we show both how to use git checkout and git restore.

I'm also curious about your experience with git restore -- do you yourself find it easier to use than git reset?

My impression is that many Git users (including me!) aren't really familiar with git restore yet, and giving both the "old" and "new" way to do it would help folks understand the new syntax.

@vermiceli

Copy link
Copy Markdown
Author

@jvns Good callout about using OR. Perhaps I was too aggressive in removing the reset version. My thinking was that a cheatsheet shouldn't have a lot of mental overhead or choices, but I understand the prevalence of reset and the novelty of the restore commands for these use cases.

I've added the original reset commands and put the restore version below with an OR.

I'm also curious about your experience with git restore -- do you yourself find it easier to use than git reset?

My impression is that many Git users (including me!) aren't really familiar with git restore yet, and giving both the "old" and "new" way to do it would help folks understand the new syntax.

I'm similar to you. I felt I owed it to myself to review git commands and read the documentation more carefully to understand git more intimately. After reading, I now try my best to use the newer commands like switch and restore. I like the new commands as they are clearer, if not a little more verbose. I'm getting more consistent about using them now, but sometimes typing habits are hard to break.

The idea behind this PR is to align the documentation with the cheat sheet. I think adding the OR is a good gentle introduction to use cases for restore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants