Tuesday, February 23, 2016

Git commands: get older version, set user email

From time to time there may be a need to play with a snapshot of an early version of code. Some Git/GitHub UI tool can help to do this, but it also just takes a few lines of command to do so. I use Mac as an example:

Check out older snapshot:
- Find the last commit you want to go back to. Copy the commit Id. It usually looks like this: 9d4f59ecf2eef3b8a46c5ba4a47a4efc27bf57b4
-  Open Terminal, change to the directory where you code base were checked out.
-  Enter: git checkout {Commit Id}
- You may see message like this:
You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

Return to latest version of master branch:
-  Enter: git checkout master

Setup user email for local Git repository:
- Enter: git config --global user.email "{user email}"

To verify user email:
- Enter: git config --global user.email