What is exactly meaning of commit command in git

Viewed 30444

commit is

A commit, or "revision", is an individual change to a file (or set of files). It's like when you save a file, except with Git, every time you save it creates a unique ID (a.k.a. the "SHA" or "hash") that allows you to keep record of what changes were made when and by who. Commits usually contain a commit message which is a brief description of what changes were made.

but i didn't got it

What is exactly meaning of commit in git and git hub?

NOTE:-This not dupli of any Q I am clear about git push

4 Answers

A commit is kind of 'object' in git, and identifies and specifies a 'snapshot' of the branch at the time of the commit.

an object is a file stored under .git/objects

eg: object e6f53bc19b182fed6cd580329747f93393504389 is a file stored at .git/objects/e6/f53bc19b182fed6cd580329747f93393504389

If the object is a commit, it records other objects that together specify the commit 'snapshot'.

Typically, the 'other objects' recorded in a commit is just two other objects - the parent commit of the current commit and the 'tree' object that specifies the actual files.

You can examine an object thus

$ git cat-file -p e6f53bc19b182fed6cd580329747f93393504389
tree 7cb95c95270b3f28a3cb6e2107f89dc7e950d93e
parent 507dbda38d769e8c69b3701cbd21a40b3a39206e
author xx <xx@xx.com> 1578053251 +0000
committer xx <xx@xx.com> 1578053251 +0000

my big commit message here!

That's it. A commit is a file stored in .git/objects that specifies a snapshot. It contains one or more references to the parent commits and a reference to a tree object.

There are 3 types of 'git object'

commit object: contains reference to commit objects and tree objects

tree object: contains references to 'blob' objects and tree objects

blob object: contains the file contents, a blob object usually represents a whole file.

(Yes, old question. But to help web searchers...)

One possible point of confusion is that, in git lingo, 'commit' is both a noun and a verb. From its glossary

As a noun: A single point in the Git history; the entire history of a project is represented as a set of interrelated commits. The word "commit" is often used by Git in the same places other revision control systems use the words "revision" or "version". Also used as a short hand for commit object.

As a verb: The action of storing a new snapshot of the project’s state in the Git history, by creating a new commit representing the current state of the index and advancing HEAD to point at the new commit.

(See https://git-scm.com/docs/gitglossary)

The git commit command captures a snapshot of the project's currently staged changes. Committed snapshots can be thought of as “safe” versions of a project—Git will never change them unless you explicitly ask it to. Prior to the execution of git commit, The git add command is used to promote or 'stage' changes to the project that will be stored in a commit. These two commands git commit and git add are two of the most frequently used.

Related