There is a question "Git: copy all files in a directory from another branch" which shows how. But it doesn't delete files that are in the current branch, but that are deleted in the other branch.
There are few solutions I usually use:
Delete the directory locally rm -r dir
, then do git checkout otherBranch -- dir
. It works, but is slow for large directories.
git checkout dir
and then git rm $(git diff --name-only otherBranch -- dir)
. It works, but I think there should be a better solution.
Is there an easier way to do it?
git reset otherBranch -- dir
git clean -df
git checkout .
This should update the contents of dir with those of the same directory on the other branch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With