git-notes
git-notes copied to clipboard
New `git switch` and `git restore` commands added in 2019
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:
- 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 mentiongit checkout
as a legacy command? - Would you rather wait for such a patch, or rewrite the section by yourself?
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.)