26 January 2020

experimental replacements for git checkout

The git checkout command has two forms. Since git 2.23 there are two experimental separte commands for each form.

  • git restore
    • replaces git checkout <path> to restore specific files to the current working directory. Examples of old/new equivalents:
      • git checkout ac36590 hamburger.md
      • git restore -s ac36590 hamburger.md
        # -s (or --source) commit or branch
      • git checkout -- tiramisu.md
      • git restore tiramisu.md
        # restore from index
      •  
      •  other interesting options
        • --staged: restore to index
        • --staged --worktree: restore to index and working directory
  •  git switch
    • replaces git checkout to switch to another branch. Examples of old/new equivalents:
      • git checkout feature
      • git switch feature

      • git checkout -b newFeature
      • git switch -c newFeature # -c or --create

No comments:

Post a Comment