How do I use git diff
to only show commit messages?
I just want the message of the commit, not the name of the files. I am trying to get a change log in Git.
To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..
Viewing a list of the latest commits. If you want to see what's happened recently in your project, you can use git log . This command will output a list of the latest commits in chronological order, with the latest commit first.
The git diff command returns a list of all the changes in all the files between our last commit and our current repository. If you want to retrieve the changes made to a specific file in a repository, you can specify that file as a third parameter.
Your file is already staged to be committed. You can show it's diff using the --cached option of git. To unstage it, just do what git status suggests in it's output ;) You can check The Git Index For more info.
You could try git log
, thus,
git log commitA...commitB
The triple dot notation '...' gives you just the commit messages for all the commits that are reachable from commitA or commitB, but not from both - i.e., the diff between commitA and commitB.
You can easily strip down to just the commit message with something like:
git log --pretty=%B commitA...commitB
Some examples
# Show a log of all commits in either the development branch or master branch since they diverged.
git log --pretty=%B development...master
# Ahow a log of all commits made to either commit b8c9577 or commit 92b15da, but not to both.
git log --pretty=%B b8c9577...92b15da
# Show a log for all commits unique to either the local branch master or local version of the origin's master branch.
git co master
git log --pretty=%B master...origin/master
# Show a log for all commits unique to either the local HEAD or local version of the origin's master branch.
git co master
# Hack, hack
git log --pretty=%B HEAD...origin/master
Use:
git log --oneline -n 10
It will print out the last n (10) commits on single lines. Just the commit messages.
You can also combine it with other log parameters, like:
git log --oneline --graph --decorate -n 10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With