git commit 命令

Git 基本操作Git 基本操作

git commit 命令將暫存區(qū)內(nèi)容添加到本地倉(cāng)庫(kù)中。

 

1. git commit 命令的語(yǔ)法

1)提交暫存區(qū)的所有內(nèi)容到本地本地倉(cāng)庫(kù)

git commit -m [message]

其中[message]可以是一些備注信息。

2)提交暫存區(qū)的指定文件到本地倉(cāng)庫(kù)

git commit [file1] [file2] ... -m [message]

3)直接提交暫存區(qū)的內(nèi)容到本地倉(cāng)庫(kù)

git commit -a

-a 參數(shù)設(shè)置修改文件后不需要執(zhí)行 git add 命令,直接來(lái)提交

 

2. 設(shè)置提交代碼時(shí)的用戶信息

提交代碼前,我們需要先設(shè)置提交的用戶信息,包括用戶名和郵箱:

$ git config --global user.name 'cainiaoplus'
$ git config --global user.email admin@cainiaoplus.com

如果去掉 --global 參數(shù)只對(duì)當(dāng)前倉(cāng)庫(kù)有效。

 

3. git commit 命令的范例

我們對(duì) hello.php 的內(nèi)容進(jìn)行改動(dòng),然后將暫存區(qū)的內(nèi)容修改,提交到本地倉(cāng)庫(kù)中。

我們使用 -m 選項(xiàng),在命令行中提供本次提交的注釋。

$ git add hello.php
$ git status -s
A  README
A  hello.php
$ git commit -m '第一次版本提交'
[master (root-commit) d32cf1f] 第一次版本提交
 2 files changed, 4 insertions(+)
 create mode 100644 README
 create mode 100644 hello.php
 

現(xiàn)在我們已經(jīng)記錄了快照。如果我們?cè)賵?zhí)行 git status:

$ git status
# On branch master
nothing to commit (working directory clean)

以上輸出說(shuō)明我們?cè)谧罱淮翁峤恢?,沒(méi)有做任何改動(dòng),是一個(gè) "working directory clean",翻譯過(guò)來(lái)就是干凈的工作目錄。

如果你沒(méi)有設(shè)置 -m 選項(xiàng),Git 會(huì)嘗試為你打開(kāi)一個(gè)編輯器以填寫提交信息。 如果 Git 在你對(duì)它的配置中找不到相關(guān)信息,默認(rèn)會(huì)打開(kāi) vim。屏幕會(huì)像這樣:

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   hello.php
#
~
~
".git/COMMIT_EDITMSG" 9L, 257C

如果你覺(jué)得 git add 提交緩存的流程太過(guò)繁瑣,Git 也允許使用 -a 選項(xiàng)跳過(guò)這一步。

git commit -a

我們先修改 hello.php 文件為以下內(nèi)容:

<?php
echo '菜鳥(niǎo)教程:www.soo66.com';
?>

再執(zhí)行 git commit 命令:

$ git commit -a -m '修改 hello.php 文件'
[master 71ee2cb] 修改 hello.php 文件
 1 file changed, 1 insertion(+)

 

Git 基本操作Git 基本操作

丰满人妻一级特黄a大片,午夜无码免费福利一级,欧美亚洲精品在线,国产婷婷成人久久Av免费高清