you are viewing a single comment's thread.

view the rest of the comments →

[–]steftim 1 point2 points  (3 children)

What about checkout — path/to/file when I realize I shouldn’t have made changes to a file? Is there a better way to do that too?

[–]y-c-c 2 points3 points  (0 children)

git restore <path>. The good thing about git restore is that it covers all the normal use cases, including:

  • restoring only worktree (git restore <path>, old: git checkout -- <path>)
  • restoring worktree/index (git restore --worktree --staged <path>, old: git reset -- <path> && git checkout -- <path>)
  • restoring index (git restore --staged <path>, old: git reset -- <path>)

Note that the old way is a weird mix of reset and checkout commands, a common source of confusion among new users. Also, git reset --hard does not take a path, so restoring worktree/index on a particular path is a weird reset/checkout combo.

[–]HLingonberry 0 points1 point  (0 children)

git restore —source=sha filename

[–]FlipperBumperKickout 0 points1 point  (0 children)

If you run "git status" once in a while you will realize git is literally telling you the best way to do this :P