How to compare branches/files in git
There are 3 major concepts :
git add
is placed into.git commit
). [see Git: What's HEAD]One more concept is Commit ID. Every commit has a ID. The commit id is a 40 digits hexadecimal, for example: 3b6ea398cc2d69212b04c29f06b8d15c0af34e34
.
# to show the last 3 commit's commit id git log -3 |
# diff working dir, staging area
git diff --color
# diff working dir, staging area, 1 file
git diff --color filename
|
# diff staging area, last commit. (--staged is same as --cached) git diff --color --staged ‹commitID› |
First, use git log
to get a commit ID.
# diff last commit, working dir git diff --color ‹commitID› |
First do
|
to find the commits IDs. Then, do
git diff 3d5cf 5aa95 myfilename
|
we only need to type the first few characters of commit id.
# show changes between {staging area, last commit} and {staging area, working dir}
git status .
|