修改文件
現(xiàn)在我想改一下倉(cāng)庫(kù)里文件的內(nèi)容瓤檐,現(xiàn)提交到倉(cāng)庫(kù)中去
$ echo "Git is very good" >> a.txt #在文件的最后添加一行
$ git status #查看當(dāng)前倉(cāng)庫(kù)的狀態(tài)
On branch master
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)
modified: a.txt
no changes added to commit (use "git add" and/or "git commit -a")
(沒有修改可以被提交憔狞,使用 “git add” 命令添加文件到暫存區(qū)族淮,或是使用“git commit -a” 命令強(qiáng)制提交當(dāng)前目錄下的所有文件)
1. 查看修改內(nèi)容(diff)
查看修改了哪些地方凳干,再?zèng)Q定是否提交晴裹。
$ git diff #查看倉(cāng)庫(kù)里未暫存內(nèi)容和倉(cāng)庫(kù)已提交內(nèi)容的差異
diff --git a/a.txt b/a.txt
index 9f4d96d..938454e 100644
--- a/a.txt
+++ b/a.txt
@@ -1 +1,2 @@
Hello Git
+Git is very good
最后一行添加了“Git is very good”。
2. 修改后提交到緩沖區(qū)(add)
把 readme.txt放到暫存區(qū)里:
$ git add a.txt
無論修改文件還是新增文件救赐,都需要執(zhí)行g(shù)it add通知git
我們現(xiàn)在看一下倉(cāng)庫(kù)的狀態(tài):
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: a.txt
3. 提交到本地倉(cāng)庫(kù)(commit)
$ git commit -m "Git is very good"
[master 42b4cbf] Git is very good
1 file changed, 1 insertion(+)
(一個(gè)文件被修改涧团,一行插入,零行刪除)
再看一下新的日志:
$ git log
commit 42b4cbf45bdd2568d189da95db42e8d127af8530
Author: breakerthb <breakerthb@126.com>
Date: Sat Oct 24 11:14:49 2015 +0800
Git is very good
commit 62dd2225d195630ed9b5e493333b84b40bae30c9
Author: Haibo Tang <Haibo Tang>
Date: Sat Oct 24 11:00:57 2015 +0800
Project init
“62dd2225d195630ed9b5e493333b84b40bae30c9” 這個(gè)就是我們剛才提交修改時(shí)創(chuàng)建的提交经磅。
4. 小結(jié)
- 修改文件的一般流程
Git文件修改一般流程
-
偷懶流程
$ git commit -a
這個(gè)命令可以直接提交所有修改泌绣,相當(dāng)于下面三條命令的總和:
$ git add
$ git diff
$ git commit
但是,它無法把新增文件或文件夾加入進(jìn)來预厌,所以赞别,如果你新增了文件或文件夾,那么就要老老實(shí)實(shí)的先git add .配乓,再git commit -a
**BTW : ** Git默認(rèn)的日志編輯軟件為nano,如果需要換成自己習(xí)慣的編輯器如vim可以使用以下命令:
$ git config --global core.editor vim
或者修改.git/config文件仿滔,在[core]下添加editor = vim這句話。
上一篇:Git基本操作(二)
下一篇:Git基本操作(四)