I am deploying application to a production server by running git pull on that production server.
As part of a backup, I am thinking of an idea to just store the current commit hash instead of copying all the files. Later on, during the restore, I would like to restore the local version of the repository from a remote origin to the saved commit hash. Ideally so it behaves like it would if I have restored whole tree including the .git folder.
To save the current commit hash, I am thinking of git log -1 --format=%H
In order to restore to a specific revision, I am aware of the git checkout hash
command. Unfortunately, this command detaches the working copy of the repository from a branch.
Is there a command or set of commands to restore the local git repository to the state it was before (aka in a transparent way with respect to further updates)? So the git pull
will update the working copy to the most recent commit in the respective branch and update the HEAD pointer etc.