【Git】Git - Log

Posted by 西维蜀黍 on 2022-04-09, Last Modified on 2023-05-02

Git Log

Shows the commit logs.

List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.

Usage

Overview

Show commit info only (Author, Date, Commit info)

# Show the sequence of commits (with Author, Date, Commit info only) starting from the current one, in reverse chronological order of the Git repository in the current working directory
$ git log

View changes briefly (contains commit SHA and comments only)

# View changes (briefly, contains commit SHA and comments only)
$ git log --oneline	

Show Commits by A File

查看特定 file 的 code change

Show code diff in each commit in a specified file

# Show the history of a particular file or directory, including differences
$ git log -p <path/to/file_or_directory>

列出修改了特定 file 的所有commit

git log --full-history -- [file path] shows the changes of a file and works even if the file was deleted.

Example:

$ git log --full-history  -- [file path]

If you want to see only the last commit, which deleted the file, use -1 in addition to the command above. Example:

$ git log --full-history -1 -- [file path]

Ref

Filter Commits

按作者查找 Commits

# Show the last N commits from a certain author:
$ git log -n number --author=author

按日期查找 Commits

# Show commits between two dates (yyyy-mm-dd):
$ git log --before="2017-01-29" --after="2017-01-17"

View Commits by Most Recent

If you want to return a specific number of commits, you can do so using the -n flag. Here’s an example of this flag in action:

git log -n 3

Merge Graphes

Show Merge Graphes

Show merges

# Show a graph of commits in the current branch using only the first line of each commit message
$ git log --oneline --graph

# Show a graph of all commits, tags and branches in the entire repo
$ git log --oneline --decorate --all --graph

Code Change

列出每个commit 的Code Change

$ git log -p 

列出特定 Commit 的Code Change

Show code diff in a specified commit

$ git log <commit_SHA> -p

影响的文件

列出每个 Commits 中修改的文件名

List file names with changes in each commit

# Show an overview of which file(s) changed in each commit
$ git log --stat

Reference