This is the second time I’ve encountered this problem. The previous time I re-downloaded the Slicer source code, compiled and merged my changes, but it was too time-consuming
As a result of deleting the .git file/folder your git repository got corrupted and Slicer’s build system failed to retrieve the required version information. You need to have a valid git repository, or instead you might be able to set the Slicer_WC_LAST_CHANGED (and other CMake variables) manually.
Do you already use the Slicercustom application template? That makes it straightforward to maintain your own customized version of Slicer.
The same just happened to me because I had move the git source repo with the sources from HOME to /opt/ and changed the ownership. (So even git status here was giving an error)