Running the following from the command line will modify your global .gitconfig
settings so whenever you’re writing your commit message in your editor, a summary of the changes will be displayed at the bottom of the screen.
I find this to be a big help in writing my commits (and reminds me to keep the changes in my commits small).
git config --global commit.verbose true
Original Behavior
When doing a git commit
, you typically see something like this in your editor
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch sf/fix-typo-105
# Changes to be committed:
# modified: README.md
#
All of these lines start with #
, marking them as comments. We have:
- a friendly message
- The branch we’re on
- The file names of the changes we’re making
Show Your Changes in the Comments
By adding --verbose
(or -v
) to our git commit
command, we can see our changes in the comments. e.g. git commit --verbose
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch sf/git-lg-to-y-m-d-105
# Changes to be committed:
# modified: README.md
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/README.md b/README.md
index ff35062..89ca417 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,6 @@ alias gds = 'git diff --staged'
alias gdno = 'git diff --name-only'
alias gdsno = 'git diff --staged --name-only'
-alias go = 'git checkoot'
+alias go = 'git checkout'
alias gl = 'git lg' # Mapped to custom alias
alias gd- = 'git d-' # Mapped to custom alias
Here we can see that we are removing a line (it has a leading -
)
-alias go = 'git checkoot'
and adding a new line in its place (it has a leading +
)
+alias go = 'git checkout'
Changes Across Multiple Files
If there are changes across multiple files, they’ll all be displayed. We are seeing the same output at the bottom of the commit comments that we would see if we ran git diff --staged
.
Always use Verbose Commits
As of Git version v2.9.0 released in June 2016, you can set Git to always use the --verbose
setting when doing a commit.
The line mentioned at the beginning of this post adds this global setting to your .gitconfig
permanently.
Leave a Reply