一, git commit 和 git commit -a
首先我们来看一下, git 文件的三种状态:
在Git 内都只有三种状态:
已提交(commited): 表示该文件已经被安全地保存在本地数据库中;
已修改(modified):表示修改了某个文件,但还没有提交保存; modified: .gitignore
已暂存(staged):表示把已修改的文件放在下次提交时要保存的清单中. new file: new_file_test.txt
mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
<span style="white-space:pre"> </span><span style="background-color: rgb(102, 102, 0);">new file: new_file_test.txt</span>
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
<span style="white-space:pre"> </span><span style="background-color: rgb(0, 102, 0);">modified: .gitignore</span>
Untracked files:
(use "git add <file>..." to include in what will be committed)
<span style="white-space:pre"> </span><span style="background-color: rgb(0, 102, 0);">new_file_test2.txt</span>
git commit 提交的是暂存区里面的内容,也就是 Changes to be committed 中的文件。
<span style="background-color: rgb(245, 245, 245);">mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ </span><span style="background-color: rgb(153, 102, 51);">git commit -m "test git commit"[master d9a2721] test git commit</span><span style="background-color: rgb(245, 245, 245);">
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 new_file_test2.txt
mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ </span><span style="background-color: rgb(153, 102, 51);">git status</span><span style="background-color: rgb(245, 245, 245);">
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
</span><span style="background-color: rgb(0, 153, 0);">modified: .gitignore</span><span style="background-color: rgb(245, 245, 245);">
Untracked files:
(use "git add <file>..." to include in what will be committed)
</span><span style="background-color: rgb(0, 102, 0);">new_file_test.txt</span><span style="background-color: rgb(245, 245, 245);">
no changes added to commit (use "git add" and/or "git commit -a")
</span>
git commit -a 除了将暂存区里的文件提交外,还提交 Changes not staged fro commit 中的文件。
mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git commit -a -m "test git commit -a"
[master c0fa5a4] test git commit -a
2 files changed, 1 insertion(+), 1 deletion(-)
create mode 100644 new_file_test2.txt
mrhero@MrsHero:~/mrhero/bitbucket_pro/fun_excel$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
new_file_test.txt
nothing added to commit but untracked files present (use "git add" to track)