git-commit
git-commit
?
軟件版本:
操作系統:ubuntu10.04
??? 內核版本:Linux version 2.6.32-36-generic
??? git 版本:git version 1.7.0.4
目錄:
1. 文件狀態
2. 提交
2.1 git commit 與 git commit -a
2.2 添加提交信息
3. 修改/取消
4. 參考資料
1. 文件狀態
一般倉庫中的文件可能存在于這三種狀態:
??? 1)Untracked files → 文件未被跟蹤;
??? 2)Changes to be committed → 文件已暫存,這是下次提交的內容;
??? 3) Changes bu not updated → 文件被修改,但并沒有添加到暫存區。如果 commit 時沒有帶 -a 選項,這個狀態下的文件不會被提交。
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: file2
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3
2. 提交
git 提交的命令為:git commit 。
2.1 git commit 與 git commit -a
git commit 提交的是暫存區里面的內容,也就是 Changes to be committed 中的文件。
$git commit[master 5b61c29] run git commit
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 file2
$git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: file
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3
git commit -a 除了將暫存區里的文件提交外,還提交 Changes bu not updated 中的文件。
$git commit -a[master bd77524] run git commit -a
1 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 file2
$git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3
2.2 添加提交信息
如果直接運行 git commit (-a) 則會默認使用 vi 添加描述。也可以使用 git config --global core.editor 命令更改為你喜歡的編輯器。還有一個方法就是使用 -m 選項直接添加提交信息。
$git commit -a -m "commit info"3. 修改/取消
有時候我們會發現有幾個文件漏了提交或者想修改一下提交信息,又或者忘記使用 -a 選項導致一些文件沒有被提交,我們希望對上一次提交進行修改,或者說取消上一次提交,這時候我們需要使用 --amend 選項。
$git commit --amend可以對上一次提交進行修改,比如我們發現漏了 file3 沒有提交,我們可以運行一下操作:
$git status# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# file3
nothing added to commit but untracked files present (use "git add" to track)
$git add file3
$git commit --amend
[master 671f5cc] commit --amend, add file3
1 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 file2
create mode 100644 file3
$git status
# On branch master
nothing to commit (working directory clean)
又或者我們發現在提交時忘記使用 -a 選項,導致 Changes bu not updated 中的內容沒有被提交,我們可以使用:
$git commit --amend -a4. 參考資料
[1] 《pro git》
轉載于:https://www.cnblogs.com/eddy-he/archive/2012/03/22/git_commit.html
總結
以上是生活随笔為你收集整理的git-commit的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux下C程序的可扩展性.
- 下一篇: Ajax(一)显示可用内存空间