My question is: Can it happen that now git will get confused and as a result of merge basically recreate the files which were deleted in steps 3,4,5 because they were present in test branch?
No. Git is never "confused" about this sort of thing. It follows clear, deterministic rules, in a consistent manner. You (or I) might be confused, but that would be just because we don't know those rules.
So let's know them. How does a merge work?
It re-enacts the contributions from both branches since the time they most recently diverged. That is the logic described in the documentation as a "3-way merge", because three points are taken into account: the point of divergence and the ends of the two branches.
Doing nothing does not count as a "contribution" in this sense. If a branch end is the same, in some regard, as the point of divergence, then nothing happened and no contribution is made by that branch in that regard.
So if master
deletes a file that was present at the point of divergence, but test
does not, then merging one into the other will result in a commit where the file is deleted — because not deleting the file is "doing nothing" which doesn't count for anything.
(However, if master
deletes a file and test
edits that file, then merging one into the other will result in a merge conflict which you will have to resolve manually. That's because they are now both contributing something, and those contributions cannot both be enacted. Still, this is not a case of Git getting confused and restoring the deleted file; it is confused, in a way, but it knows that, so it takes no action on the matter, leaving it to you to decide what to do. As long as you don't force the resolution of the conflict beforehand by specifying an ours
or theirs
strategy, you still won't accidentally restore the file.)