Chris Hansen
Chris Hansen

Reputation: 8687

How to get 'git diff' to only show commit messages

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.

Upvotes: 22

Views: 20606

Answers (4)

Anton Rybalko
Anton Rybalko

Reputation: 1314

In addition to Simon Clewer's answer:

git log master..dev --no-merges --pretty='format:%cs %s'

It prints only subjects of commits between master and development branches (without merge commits). Something like this:

2020-12-31 Hot fix
2020-12-30 Change some stuff
2020-12-29 Add the feature

Changes between local and remote branches:

git log HEAD..origin --no-merges --pretty='format:%cs %s'

See also What are some good ways to manage a changelog using Git?.

Upvotes: 9

Simon Clewer
Simon Clewer

Reputation: 511

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

Upvotes: 18

Simon
Simon

Reputation: 764

git log --pretty=%B

will show you the last commit messages.

In case you want to limit the number of commit messages shown by a number, N, you can do this by providing an additionally -N, e.g.,

git log -3 --pretty=%B

for the last three commit messages.

Upvotes: 3

CodeWizard
CodeWizard

Reputation: 142532

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

Upvotes: 5

Related Questions