本文git版本1.9.6git
git代碼提交層次圖bash
1、修改本地代碼查看差別ide
2、移除代碼ui
3、重命名代碼3d
1.一、當咱們修改本地code的時候,使用命令能夠看到文件的狀態的處於修改狀態;而後咱們能夠將code add 而後進行commit;code
咱們能夠看到code修改什麼地方,修改了什麼內容;blog
$ git status -s $ echo 'puts "hello world!"' >> hello.rb $ git diff hello.rb
1.二、將此添加到staging area區域,再次查看文件狀態ip
$ git add hello.rb $ git status -s $ git diff hello.rb
能夠看到文件狀態表示staging area和repository區域之間發生了改變;get
能夠看出 diff 選項 能夠用於查看working directory 和 staging area 區域間的文件變化;it
1.三、使用 git diff HEAD 能夠看到 working directory 和 repository 區域間 的文件變化
$ git diff HEAD hello.rb
1.四、使用git diff --staged 能夠看到 staging area 和 repository 區域間的文件變化
$ git diff --staged hello.rb
$ git diff --staged --stat hello.rb # 輸出簡要信息
這是文件改變輸出變化的命令
二、移除代碼
2.一、將hello.rb的文件刪除,(此步至關於 add 的逆操做)查看文件狀態;將結果 commit 到 repository;查看文件狀態;
$ git rm hello.rb $ ls $ git status -s
能夠看出執行 rm 的時候就已經將本地文件刪除掉了;
執行 status 能夠看到文件狀態標識爲 D 表示處理已刪除狀態;
$ git commit -m "first del" hello.rb
2.二、若是咱們不想刪除working directory 區域的文件,只想刪除 staging area 區域的文件,能夠執行 git rm --cached 命令;
$ git rm --cached hello.rb
在執行 git status -s 後,D 和 ?? 是什麼意思呢? D 表示 staging area 和 repository 區域的差異,表示 hello.rb 處理刪除狀態, 因此在working directory 區域的 hello.rb就處於 Untracked 狀態;
2.三、若是想恢復staging area 區域的hello.rb,能夠從repository 拉取 或 從 working directory 提交上去 (在本地沒有改變的時候,若是改變,那提交的是新文件,也不會恢復到以前的文件);
$ git reset hello.rb # 從 repository 拉取
三、重命名代碼
3.一、將本地文件 README.txt 重命名爲 README.md ;查看文件狀態,而後提交到 repository ;
$ git mv README.txt README.md $ git commit -m "first rename filename"
tips: 上面 執行 commit 的時候,實際上是執行了兩個步驟,把 README.txt 刪除提交,把 README.md 提交; 看下圖就明白了;
其實在 git 中,文件的名字和內容能夠分開理解(就像 Python 的 變量和值);在git中,若是兩個文件的內容同樣,他就認爲是一個重命名;