git-notes icon indicating copy to clipboard operation
git-notes copied to clipboard

New `git switch` and `git restore` commands added in 2019

Open amiryal opened this issue 3 years ago • 1 comments

From the release notes:

  • Two new commands "git switch" and "git restore" are introduced to split "checking out a branch to work on advancing its history" and "checking out paths out of the index and/or a tree-ish to work on advancing the current history" out of the single "git checkout" command.

My questions are:

  1. How would you feel about a patch that rewrites the confusion about checkout versus reset section in what/gcs.mkd to feature the twe new commands, and only mention git checkout as a legacy command?
  2. Would you rather wait for such a patch, or rewrite the section by yourself?

amiryal avatar Jul 11 '21 12:07 amiryal

For reference, here are my revised cheatsheet and its old version:

Command Current branch head (updates .git/refs/heads/cb) Index Working tree Current branch (updates .git/HEAD)
git restore -W [--source=<commit>] -- <path>
git restore -S [--source=<commit>] -- <path>
git restore -S -W [--source=<commit>] -- <path>
git reset --soft <commit> --
git reset <commit> --
git reset --hard <commit> --
git switch <branch>
git switch --detach <somewhere>

(Note how detaching HEAD is now explicit with git switch. The section about detached HEAD would need to be updated accordingly as well.)

Command Current branch head (updates .git/refs/heads/cb) Index Working tree Current branch (updates .git/HEAD)
git reset [<commit>] -- <path>
git checkout [<commit>] -- <path>
git reset --soft <commit> --
git reset <commit> --
git reset --hard <commit> --
git checkout <somewhere> --

(Note the missing first line, compared to the revised table. There might be a way to simulate git restore -W with git checkout, but I haven’t made any serious research towards that.)

amiryal avatar Jul 11 '21 12:07 amiryal