Git Examples
# Find the commit where this a file (foo.js) was first added (you can do the same for deleted, modified, etc):
git log --diff-filter=A -- foo.js
# Show the changes made in the most recent commit
git show
# Show all changes between a commit and HEAD
git diff 00ad6dc
# Show the changes for a single commit
git show 00ad6dc
git diff 00ad6dc^ 00ad6dc (not tested...)
git config --global user.name "Your Name"
git config --global user.email "your_email@whatever.com"
git config --global core.editor "vim"
git config --global core.autocrlf input
git config --global core.safecrlf true
git commit messages:
https://chris.beams.io/posts/git-commit/
git notes - http://gitimmersion.com/
# Create repo
mkdir newrepo
cd newrepo
git init
# Add file to repo
git add hello.rb
git commit -m "First Commit"
# Check status
git status
# Flow example
git branch foo
git checkout foo
edit/test/etc
git add .
git commit
checkout master
merge foo
# Discard changes in a file by stomping on it with a copy from the repo:
git checkout hello.rb
# Checkout an older version of a file (use git log to see the hash)
git checkout 00ad6dc
# Checkout the latest version of the master branch
git checkout master
# Made a tiny mistake? Amend the previous commit:
git add hello.rb
git commit --amend -m "Add an author/email comment"
# Move a file, version 1
mkdir lib
git mv hello.rb lib
git status
# Move a file, version 2
mkdir lib
mv hello.rb lib
git add lib/hello.rb
git rm hello.rb
# add a tag
git tag v1
# remove a tag
git tag -d v1
# list all tags
git tag
# Checkout the version immediately prior to the current version
git checkout v1
# Undo the last commit
git revert HEAD
# Rewrite the current branch to point to the specified commit (in this case, the commit with the tag v1):
git reset --hard v1
###############################################################################
# See the change log
git log
# pretty log
git log --pretty=oneline
git log --pretty=oneline --max-count=2
git log --pretty=oneline --since='5 minutes ago'
git log --pretty=oneline --until='5 minutes ago'
git log --pretty=oneline --author=
git log --pretty=oneline --all
git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago'
# This is nice:
git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
# I like this one best, but needs hours/minutes/seconds in the timestamp
git log --pretty=format:'%h %ad | %an | %s%d' --graph --date=short
man git-log
###############################################################################
# Git global setup:
git config --global user.name "Jeremy Frank"
git config --global user.email "jfrank@dmotorworks.com"
# Create Repository
mkdir jeremy-scripts
cd jeremy-scripts
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@gitit.dmotorworks.com:jfrank/jeremy-scripts.git
git push -u origin master