1. git reflog
git reflog作用为查看所有分支中,对commit的操作,包括添加,删除。类似于一个对commit操作的历史记录,如果有不小心删除的commit,可以进行查看提取恢复。
从根本上说,任何修改引用或更改分支头HEAD的git操作都会记录。
toney@sw2:~/work/project/dragon/core/code/future$ git reflog
dccb644 HEAD@{0}: checkout: moving from dev_dragon to AAA
dccb644 HEAD@{1}: checkout: moving from master to dev_dragon
5daf50b HEAD@{2}: clone: from cameo_git:icore
toney@sw2:~/work/project/dragon/core/code/future$
比如上述第一条,dccb644为commit最后7位,对该commit的操作是切换分支。
也可指定分支名查看:
toney@sw2:~/work/project/dragon/core/code/customer/cus_dlinkg2$ git reflog AAA
e10192d AAA@{0}: rebase -i (finish): refs/heads/AAA onto 295671c0b394db080fb8d8ef1fe5ada3b2771806
fc3a425 AAA@{1}: rebase -i (finish): refs/heads/AAA onto 295671c0b394db080fb8d8ef1fe5ada3b2771806
436d7cf AAA@{2}: commit: c
94f9dc2 AAA@{3}: rebase finished: refs/heads/AAA onto 42947bf9888c01669ed3541ddb7d585502f38bc8
d54bfd2 AAA@{4}: commit: b
a7899fd AAA@{5}: commit: a
11316b0 AAA@{6}: branch: Created from HEAD
2. git diff
git diff比较文件修改的差异结构如图:
2.1 三种情况举例:
- 文件中添加123456:
查看修改结果: