Instead of git reset
, you'll want to use git checkout
in step 3:
git fetch -a -t origin
git merge --no-commit --no-ff TAG
git checkout HEAD -- Z/
git commit
In general, git checkout
is the way to say "make something in my working copy look like the reference I describe," whether it's your entire working copy, a file, or a subdirectory. That's exactly what you want here: during the merge, you want to say "scrap any changes that were merged in, and instead make directory Z look exactly like it does in HEAD". (Remember that HEAD hasn't moved yet because the merge hasn't been committed!)
git reset
is generally used for manipulating some subset of HEAD, the index (changes that you've staged for commit), and the working copy together to some state. Reset can be confusing, but there's a good, in-depth write-up on git-scm.com if you want more information.