8. Git 提交更改

2018-08-04 14:17 更新

目的

學習如何提交更改到倉庫。

提交更改

好,關(guān)于暫存談得夠多了。讓我們提交已暫存的內(nèi)容到倉庫。

當你先前使用 git commit 命令提交 hello.rb 文件的初始化版本 到倉庫時,你在命令行上的 -m 選項可以包含注釋。commit 命 令將允許你交互式地編輯提交的注釋?,F(xiàn)在讓我們試試看。

如果你從命令行忽略 -m 選項,那么 Git 將帶你到所選的編輯器 中。編輯器按以下列表選擇(使用優(yōu)先級順序):

GIT_EDITOR 環(huán)境變量
core.editor 配置設(shè)置
VISUAL 環(huán)境變量
EDITOR 環(huán)境變量

我已將 EDITOR 變量設(shè)置為 emacsclient。

那么,現(xiàn)在提交并檢查狀態(tài)。

$ git commit

你應該在編輯器中看到下面的內(nèi)容:

|
# 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.rb
#

在第一行,輸入注釋:“Using ARGV”。保存文件,并退出編輯 器。你應該看到:

git commit
Waiting for Emacs...
[master 569aa96] Using ARGV
 1 files changed, 1 insertions(+), 1 deletions(-)

“Waiting for Emacs…”來自發(fā)送文件到正在運行的 Emacs 程序 emacsclient,并等候關(guān)閉文件。其余的輸出是標準的提交信息。

檢查狀態(tài)

最后,讓我們再檢查下狀態(tài)。

$ git status

你應該看到:

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

工作目錄是干凈的,且準備讓你繼續(xù)。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號