先对本机的readme.txt文件修改,比如添加一个“distribution”。用’git status’命令查看仓库当前状态,显示
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: file1.txt
deleted: file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
意思是上面的文件已经被修改过,但是还没提交到仓库,用git add 文件名
提交到仓库。
这时还可以git diff
查看做了哪些修改
$ git diff readme.txt
diff --git a/readme.txt b/readme.txt
index b0354bd..bf8ef1b 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distribution version control system.
Git is a free software
意思是往里添加了一个单词“distribution”。这时已经知道做了哪些修改,再提交就放心多了。和提交新文件相同,提交修改都是两步走。第一步git add
是
然后使用git add readme.txt
命令提交到仓库.没有任何显示就对了。我们可以git status
查看当前仓库状态。
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: file1.txt
new file: file2.txt
modified: readme.txt
告诉我们需要提交的修改包括readme.txt文件,接着使用’git commit -m “add distrubution”’
$ git commit -m "add distributed"
[master 4ff027d] add distributed
1 file changed, 1 insertion(+), 1 deletion(-)
再使用git status命令查看仓库当前状态,显示
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: file1.txt
deleted: file2.txt
no changes added to commit (use "git add" and/or "git commit -a")
git告诉我们当前没有需要提交的修改。(使用git add and/or git commit -a命令提交)
最后总结:随时使用git status
查看当前状态,是否有文件修改过,如果你要是不记得修改了那个文件,可以用git diff
查看做了哪些修改。然后用git add 文件名
和git commit -m "修改说明"
提交修改和提交新文件。