git commit --分支的提交

背景

基于上一篇:git checkout -分支的新建的背景,继续了解使用的命令git commit

官网语法介绍

NAME
git-commit - Record changes to the repository

SYNOPSIS

git commit [-a | --interactive | --patch] [-s] [-v] [-u] [–amend]
[–dry-run] [(-c | -C | --fixup | --squash) ]
[-F | -m ] [–reset-author] [–allow-empty]
[–allow-empty-message] [–no-verify] [-e] [–author=]
[–date=] [–cleanup=] [–[no-]status]
[-i | -o] [–pathspec-from-file= [–pathspec-file-nul]]
[-S[]] [–] […​]

DESCRIPTION
Create a new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it (unless no branch is associated with the working tree, in which case HEAD is “detached” as described in git-checkout[1]).

The content to be committed can be specified in several ways:

by using git-add[1] to incrementally “add” changes to the index before using the commit command (Note: even modified files must be “added”);

by using git-rm[1] to remove files from the working tree and the index, again before using the commit command;

by listing files as arguments to the commit command (without --interactive or --patch switch), in which case the commit will ignore changes staged in the index, and instead record the current content of the listed files (which must already be known to Git);

by using the -a switch with the commit command to automatically “add” changes from all known files (i.e. all files that are already listed in the index) and to automatically “rm” files in the index that have been removed from the working tree, and then perform the actual commit;

by using the --interactive or --patch switches with the commit command to decide one by one which files or hunks should be part of the commit in addition to contents in the index, before finalizing the operation. See the “Interactive Mode” section of git-add[1] to learn how to operate these modes.

The --dry-run option can be used to obtain a summary of what is included by any of the above for the next commit by giving the same set of parameters (options and paths).

If you make a commit and then find a mistake immediately after that, you can recover from it with git reset.

自我认识

在用git进行版本控制时,需要执行commit命令,将索引内容添加到本地仓库中,常用的有:

git commit -m “提交修改的描述”
这个是提交当前页面或者你选中的页面提交,但是你已经工作了两天,可能改动的页面自己都记不清楚了,也可能进行了文档的删除、新增以及更改,此时若要全部添加到索引中去,最省事的使用
git commit -a -m "描述”

在这里, -a 的选项只将所有被修改或者已删除的且被git管理的文档提交到仓库中。若是提交后,想修改注释,可以借助

git commit --amend

另外,git是不会主动记录你对文档进行的更新操作,除非你对他发出号令(比如使用git add命令)

写在最后

点击查看git commit官网介绍

commit的本质是修改了当前分支的头指针(refs/heads)

在这里插入图片描述