Git Reference

Commands Used: 
git log =  git history 
git log --all --decorate --oneline --graph = commit history graph
git branch (branch-name) = create a branch
git checkout (branch-name) = checkout a branch/move head pointer
git commit -a -m "commit message" = commit all modified and tracked files in on command (bypass separate 'git add' command)
git commit -n -m "commit message" = commit all modified withour code validation
git commit --amend -m "<new message>"
git diff master..SDN = diff between 2 branches 
git merge (branch-name) = merge branches (fast-forward and 3-way merges)
git branch --merged = see branches merged into the current branch
git branch -d (branch-name) = delete a branch, only if already merged
git branch -D (branch-name) = delete a branch, including if not already merged (exercise caution here)
git merge --abort = abort a merge during a merge conflict situation
git checkout (commit-hash) = checkout a commit directly, not through a branch, results in a detached HEAD state
git stash = create a stash point 
git stash list = list stash points 
git stash list -p = list stash points and show diffs per stash
git stash apply = apply most recent stash
git stash pop = apply most recent stash, and remove it from saved stashes 
git stash apply (stash reference) = apply a specific stash point
git stash save "(description)" = create a stash point, be more descriptive

How do you roll back (reset) a Git repository to a particular commit?
git log --stat
git log --pretty=oneline --abbrev-commit
git reset --hard <tag/branch/commit id>
git show HEAD

git reset HEAD^ 
git push -u origin staging --force

Clean all untrack files
git clean -df

Get history of GIT activities:
git reflog

Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits:

git reset --hard HEAD~1
git diff <commit 1 id> <commit 2 id>
git difftool HEAD HEAD~!

This entry was posted in Technologies. Bookmark the permalink.