Tuesday, September 27, 2016

Git refresher

git init - Initializes my directory for a Git project

Git project has three parts:
1 - Working Directory - Where I create, edit, delete, and organize files
2 - Staging Area - Where I list changes I make to the working directory
3 - Repository - Where Git permanently stores those changes as different versions of the project

git status - Check status of changed files

git add filename - Adds file to Git project so Git watches for changes
git add filename1 filename2 - Add multiple files to Git project

git diff filename - Identifies changes within the file

git commit -m "Message describing commit"

git log - View log of commits

git show HEAD - Displays the message for the HEAD commit plus all the file changes that were committed.
HEAD = The commit I am currently on

git checkout HEAD filename - Revert filename back to the HEAD commit

git reset HEAD filename - Unstage (reset) filename from staging area.
Useful for when I accidentally added a file to the staging area and do not want to commit it.

get reset <SHA> - Rewind back to commit identified by SHA value.  SHA value is first 7 characters.
SHA values can be seen in the git log (use "git log" to view)