git diff
Workspace and staging area
git diff 比较所有有变化文件
git diff file 比较特定文件
Staging area and local warehouse
The default is the comparison between the temporary storage area and HEAD
git diff --cached 比较暂存区和 HEAD 所有变化文件
git diff --cached file 比较暂存区和 HEAD 特定文件
Workspaces and local repositories
Can be compared with the commit id of any local warehouse
git diff e69de29 和 commit id 比较
git diff HEAD 和 HEAD 比较
git diff dev 和 dev 分支比较
View the diff between two commits
A space can be written in the middle, or two dots can be written, the effect is the same.
git diff commit1 commit2
git diff commit1..commit2
View the difference between commitA and commitB's merge base and commitB of the two commits.
A bit of a mouthful. First explain the merge base.
As shown in the figure, the merge base of commit C and commit G is commit E
The merge base of C and G is E, C...G
which means the diff between E and G.
git diff C...G
等价于 git diff $(git merge-base C G) G
git merge-base 用来获取 C G 的 最近的基点
This kind of three-point diff is still very useful. For example, we want to see what changes have been made to the topic branch since it was branched, and it can be used git diff G...C
.
The previous can git diff G...C
also use the branch name, git diff master...topic
.
Specific documents can be checked.
git diff G...C -- a.txt
Among them – is to separate the file names, which can be omitted under normal circumstances.
Directly compare the differences of two files
Direct comparison means that the contents of the current two files are directly compared without involving versions.
git diff --no-index a.txt b.txt