User Tools

Site Tools


git_commit

This is an old revision of the document!


Overview

Miscellaneous notes on git commit, using the Linux kernel source as an example.

SYNOPSIS

git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
           [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
           [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
           [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
           [--date=<date>] [--cleanup=<mode>] [--[no-]status]
           [-i | -o] [-S[<keyid>]] [--] [<file>...]

Examining what is about to be committed

git status

See which files are staged for committing:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   MAINTAINERS
	modified:   README

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

	modified:   Makefile
$

git diff --cached

To see the entire difference about to be committed:

$ git diff --cached                            [or --staged]
diff --git a/MAINTAINERS b/MAINTAINERS
index 41ce5f4ad838..202d67e2facb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1,4 +1,4 @@
-
+New stuff in MAINTAINERS
 
        List of maintainers and how to submit kernel changes
 
diff --git a/README b/README
index 669ac7c32292..3db2a5b35089 100644
--- a/README
+++ b/README
@@ -1,3 +1,5 @@
+New stuff in README
+
 Linux kernel
 ============
 

git diff --cached --stat

For a histogram-style summary, add --stat:

$ git diff --cached --stat
 MAINTAINERS | 2 +-
 README      | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
$

Template

This might be worth setting at the system level.

$ git config --global commit.template ~/.gitmessage.txt

Example ~/.gitmessage.txt:

Subject line (try to keep under 60 characters)

Multi-line description of commit,
feel free to be detailed.

[Ticket: X]
git_commit.1550651323.txt.gz · Last modified: 2019/02/20 08:28 by rpjday