git 中 commit 命令的确切含义是什么

What is exactly meaning of commit command in git

提交是

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.

但我没听懂

git 和 git 中心中 commit 的确切含义是什么?

注意:-这不是任何问题的重复我很清楚git push

更改代码后,您将“提交”。

提交设置有关您所做的更改的消息。 提交还保存了代码的修订版,您可以随时将代码还原到任何版本。

一直以来,这方面的完美例子就像一棵树。更准确地说,是源代码树。这将完美地解释源代码树上的 git branch

每在“主人”上提交一个点,主人就是树干。

您可以向树中添加一个分支,并仅在此分支上添加更多提交。 修改完成后,可以将修改合并到master上。

所以综上所述,git被用作代码版本管理器。知道如何处理冲突,将几个不同的版本合并为一个版本。

这是比较两个不同代码版本(提交)的屏幕截图

希望对你有所帮助:)

(是的,老问题。但是为了帮助网络搜索者...)

一个可能的混淆点是,在 git 行话中,'commit' 既是名词又是动词。来自其词汇表

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.

(见https://git-scm.com/docs/gitglossary

提交是 git 中的一种 'object',并在提交时标识和指定分支的 'snapshot'。

对象是存储在 .git/objects

下的文件

例如:对象 e6f53bc19b182fed6cd580329747f93393504389 是存储在 .git/objects/e6/f53bc19b182fed6cd580329747f93393504389

的文件

如果对象是提交,它会记录一起指定提交的其他对象'snapshot'。

通常,提交中记录的 'other objects' 只是另外两个对象 - 当前提交的父提交和指定实际文件的 'tree' 对象。

你可以这样检查一个对象

$ 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!

就是这样。提交是存储在 .git/objects 中的文件,用于指定快照。它包含对父提交的一个或多个引用以及对树对象的引用。

有3种'git object'

提交对象:包含对提交对象和树对象的引用

树对象:包含对 'blob' 对象和树对象的引用

blob对象:包含文件内容,一个blob对象通常代表整个文件。

git commit 命令捕获项目当前暂存更改的快照。提交的快照可以被认为是项目的“安全”版本——Git 永远不会更改它们,除非您明确要求它这样做。在执行 git commit 之前, git add 命令用于提升或 'stage' 对将存储在 commit 中的项目的更改。 git commit 和 git add 这两个命令是最常用的两个命令。