I want to reset the contents of my working directory to match some revision without changing the commit my current branch is pointing to, as git reset
As jthill mentioned in his answer, in the general case git read-tree
can do what you want:
git read-tree
-um
commit
If, however, you want to be able to checkout/reset a subdirectory instead of the entire tree, you'll need a somewhat more complex command:
git diff
--cached
commit
--
subdir
|
git apply-R --index
Since this command is much longer than the previous, if you plan on using it frequently you'll probably want to set up an alias for it:
git config --global alias.reset-checkout '!f() { git diff --cached "$@" | git apply -R --index; }; f'
And use like:
git reset-checkout 451a9a4 -- path/to/directory
Or just:
git reset-checkout 451a9a4
git read-tree
-um
commit
resets the index and worktree to that commit (the -m
option says to merge what's being read into the index -- with just the one tree and index this is a bit of a degenerate case), the u
option says to update the worktree when done).