View changes of file in staging
git diff --staged <filename>
View details of commits in local repo
git log <remote>/<branch>..HEAD
eg: git log origin/master..HEAD
Find all commits for a file
git log --follow <filename>
Git Diff explained in picture
Although this basic, we have relied on GUIs to understand our diffs. Using the CLI’s diff would be foreign to us. Found a really good image to help us.
Recollect your steps of previous commits you have worked on
Wrote alot of commits and so have others? Can’t remember which one you wrote yesterday? Need to find it?
git reflog
Each time a branch is updated to point to a new reference, an entry is written in the reflog to say where you were.
Here’s a good blog to understand better.
Show files involved in the commit
git log --name-status <commit>
Show all commits in a range
git log <previous>..<tillnow>
you can use this for:
- tag names
v1.1..v1.2
- commit hashes
0de96..56313
- branches
feature\me..origin\feature\me
See recently used branches by the last commit (i.e. branches ordered by most recent commit)
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:cyan)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) %(contents:subject) | %(color:magenta)%(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
Source: http://stackoverflow.com/q/5188320/1391963
best to make this into an alias
git config --global alias.recent for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:cyan)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) %(contents:subject) | %(color:magenta)%(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
Change the colors as you wish.
Find commits with filter
git log --grep='<pattern>'
limits to commits whose log message has a line that matches