Introduction
I recently got into a situation, where changes made to a file was committed, but I was not sure which commit captured those changes. So, I wanted to know the files changed in past commits. One of the easiest way to do this is to simply check the history of your repo on GitHub or GitLab etc. But I didn’t push my local commits, since I wanted to ensure that things are perfect before I push. I found the following commands to be useful in this regard.
Method 1: Using git log with stat option
Among the many ways available, I found this one to be quite elegant. This is my preferred method.
Command
git log --stat --pretty=short --graph
Output
* commit 2514abdb6e5274167509a892b10244f336fff290 (HEAD -> main, origin/main)
| Author: Sidharth R <122173059+hugo-sid@users.noreply.github.com>
|
| chore(ci): change emojis used in changelog
|
| .github/workflows/release.yml | 4 ++--
| 1 file changed, 2 insertions(+), 2 deletions(-)
|
* commit 4e83639c42cec577c8e592a6dbc930b296348ffc
| Author: Sidharth R <122173059+hugo-sid@users.noreply.github.com>
|
| chore(ci): add comments for GitHub action workflow trigger
|
| .github/workflows/pr-labeler.yml | 3 ++-
| 1 file changed, 2 insertions(+), 1 deletion(-)
|
* commit 4438214567c515feeabaa61204c4c3b1c1f0da02
| Author: Sid <122173059+hugo-sid@users.noreply.github.com>
|
| docs: update instructions for adding favicon
|
| README.md | 2 +-
| 1 file changed, 1 insertion(+), 1 deletion(-)
|
* commit 04afe81c635bf6129c841d9c9b72b13065e4eec0 (tag: v1.2.0)
| Author: Sid <122173059+hugo-sid@users.noreply.github.com>
|
| chore(main): release 1.2.0 (#43)
|
| CHANGELOG.md | 14 ++++++++++++++
| 1 file changed, 14 insertions(+)
Command explanation
git log
- command to view git commit history--stat
- option to show abbreviated stats for each commit--pretty=short
- option to view only the first line of the commit message--graph
- option to view the commit history in a graph format
The --stat
option prints below each commit entry, a list of modified files, how many files were changed, and how many lines in those files were added and removed. It also puts a summary of the information at the end 1.
Another useful option is --pretty
. This option allows us to modify the display of command output. A few built-in option values are available, which are:
oneline
- the oneline value for this option prints each commit on a single line, which is useful if you’re looking at a lot of commitsshort
,full
, andfuller
- these values show the output in roughly the same format but with less or more information, respectively
Method 2: Using git log with numstat option
Command
git log --numstat
Output
Date: Sun May 14 19:19:48 2023 +0530
chore(ci): change emojis used in changelog
2 2 .github/workflows/release.yml
commit 4e83639c42cec577c8e592a6dbc930b296348ffc
Author: Sidharth R <122173059+hugo-sid@users.noreply.github.com>
Date: Sun May 14 19:17:57 2023 +0530
chore(ci): add comments for GitHub action workflow trigger
2 1 .github/workflows/pr-labeler.yml
commit 4438214567c515feeabaa61204c4c3b1c1f0da02
Author: Sid <122173059+hugo-sid@users.noreply.github.com>
Date: Sat May 13 08:34:36 2023 +0530
docs: update instructions for adding favicon
1 1 README.md
commit 04afe81c635bf6129c841d9c9b72b13065e4eec0 (tag: v1.2.0)
Author: Sid <122173059+hugo-sid@users.noreply.github.com>
Date: Wed May 10 09:54:07 2023 +0530
chore(main): release 1.2.0 (#43)
14 0 CHANGELOG.md
At first glance, this output may seem a bit cryptic. Let me explain. The numbers in the first two columns show the number of insertions and deletions made to the file respectively. The third column shows the name of the file.
Command explanation
git log
- command to view git commit history--numstat
- option to show abbreviated stats for each commit 2
Method 3: Using git log with name-only option
Command
git log --name-only --oneline
Output:
2514abd (HEAD -> main, origin/main) chore(ci): change emojis used in changelog
4e83639 chore(ci): add comments for GitHub action workflow trigger
.github/workflows/pr-labeler.yml
4438214 docs: update instructions for adding favicon
README.md
04afe81 (tag: v1.2.0) chore(main): release 1.2.0 (#43)
CHANGELOG.md
82eee54 chore(repo): add info regarding changelog
CONTRIBUTING.md
685ebf6 feat: add support for comments (#44)
README.md
exampleSite/config.toml
layouts/_default/single.html
layouts/partials/comments.html
4abd77b chore(repo): update CONTRIBUTING.md
CONTRIBUTING.md
225237f chore(repo): update README.md
README.md
a674bf9 (tag: v1.1.2) chore(main): release 1.1.2
CHANGELOG.md
154883e ci: add stale sction
.github/workflows/stale.yml
d0c5acb (tag: v1.1.1) chore(main): release 1.1.1 (#37)
CHANGELOG.md
Command explanation
--name-only
- shows only the names of the changed files for each commit 3--oneline
- show only the first line of each commit message
References
https://stackoverflow.com/questions/1230084/how-to-have-git-log-show-filenames-like-svn-log-v