Augmenting @jthill's approach, I would do
git merge --no-commit --no-ff trunk
git diff --name-only -z --diff-filter=A @ | xargs -0 git rm -f
rm .git/MERGE_*
git commit
This would make git forget that it's doing a merge and would prevent files from being deleted when you finally want to merge back into your trunk.
As a comment though, this is not a very sustainable workflow, even if you write your own script to automatically do this every time. It's worth asking the question of why you feel like you need to do this.
It might be that:
- The repo is too large -- Then you should think about splitting up the code
- Your work is logically separate -- Then you should definitely think about splitting up the code
- There is broken work in trunk -- Then you should implement a new workflow that doesn't merge broken code into trunk
Alternative solutions if you don't want to modify your workflow would be to:
If you want to overwrite the changes completely
git checkout trunk -- *
git commit
If you want to completely overwrite some files
git checkout trunk -- file2
git commit
Or, interactive rebase gives you the option to only select the commts you want. This also won't result in files being deleted later on
git rebase -i trunk
Personally, I'd look into changing your workflow. If you have more information on your situation, we'd be able to help you figure out other solutions.