Git 2.23, released on August 16, 2019, introduces git switch for changing branches and git restore for restoring files, separating two jobs previously handled by git checkout. For development teams revising their instructions, the distinction inside restore matters too: its --staged option alone changes the staging area without changing the working file, while its default operation changes the working file. Choosing the wrong destination can discard edits a developer meant to keep. [S1][S2][S4]

Git keeps a distinction between the working tree—the files being edited—and the index, the staging area holding what is prepared for a commit. In the version 2.23 manual, restore without a destination option updates only the working tree, taking its content from the index by default. For a tracked file edited again after staging, restoring that file therefore takes it back to the staged version, not necessarily the last committed version. [S2][S4]

Adding --staged changes both the destination and the default source. The manual says git restore --staged hello.c restores the index entry from HEAD; --staged alone does not restore the working file. To change both copies, the release's manual requires an explicit --source as well as --staged --worktree. Its example git restore --source=HEAD --staged --worktree hello.c replaces both with the committed version. These are different instructions: removing a change from the next commit is not the same operation as discarding that change from the file being edited. [S2]

Restoration can also mean deletion. Git 2.23's restore defaults to no-overlay mode, which removes tracked files absent from the selected source tree so the result matches that source. The --overlay option instead prevents removal during restoration. For a team writing a procedure to recover selected files from an older revision, this means the procedure needs to say whether absent files should disappear or remain. The option controls removal, not whether restoration writes files. [S2]

Branch switching has a different protection. Git's switch manual says a clean working tree and index are not always required, but the command aborts if switching would lose local changes unless told otherwise with --discard-changes or --merge. Those options are not equivalent: the first throws local changes away, while the second attempts a three-way merge and can leave conflicts to resolve. Both new commands are marked experimental in their 2.23 manuals, with behavior subject to change. Team instructions adopting them should name the required Git version as well as the intended operation. [S2][S3]

Source documents

  1. Git 2.23 release noteshttps://raw.githubusercontent.com/git/git/5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9/Documentation/RelNotes/2.23.0.txt
  2. Git 2.23.0 git-restore manualhttps://raw.githubusercontent.com/git/git/5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9/Documentation/git-restore.txt
  3. Git 2.23.0 git-switch manualhttps://raw.githubusercontent.com/git/git/5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9/Documentation/git-switch.txt
  4. GitHub: Highlights from Git 2.23https://github.blog/open-source/git/highlights-from-git-2-23/