A necessary condition for a generally covariant scalar-tensor theory to be ghostfree is that it contains no extra degrees of freedom in the unitary gauge, in which the Lagrangian corresponds to the spatially covariant gravity. Comparing with analysing the scalar-tensor theory directly, it is simpler to map the spatially covariant gravity to the generally covariant scalar-tensor theory using the gauge recovering procedures. In order to ensure the resulting scalar-tensor theory to be ghostfree absolutely, i.e., no matter if the unitary gauge is accessible, a further covariant degeneracy/constraint analysis is required. We develop a method of covariant 3+1 correspondence, which map the spatially covariant gravity to the scalar-tensor theory in 3+1 decomposed form without fixing any coordinates. Then the degeneracy conditions to remove the extra degrees of freedom can be found easily. As an illustration of this approach, we show how the Horndeski theory is recovered from the spatially covariant gravity. This approach can be used to find more general ghostfree scalar-tensor theory.