1. 程式人生 > >第5章 檔案管理和索引

第5章 檔案管理和索引

5.1 關於索引的一切
Git的索引不包含任何檔案內容,它僅僅追蹤你需要提交的那些內容。當執行git commit命令的時候,Git會通過檢查索引而不是工作目錄來找到提交的內容。

5.2 Git中的檔案分類
Git將所有檔案分層3類:
已追蹤的
:已追蹤的檔案是指已經在版本庫中的檔案,或者是已暫存到索引中的檔案。git add
被忽略的
:被忽略的檔案必須在版本庫中被明確宣告為不可見或被忽略,即使它可能會在你的工作目錄中出現。
未追蹤的
:為追蹤的檔案是指那些不在前兩類中的檔案。

Administrator@BGUJ9QLXIRFWC3S MINGW32
/d/gittest $ mkdir my_stuff Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest $ cd my_stuff/ Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff $ git init Initialized empty Git repository in D:/gittest/my_stuff/.git/ Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch master Initial
commit nothing to commit (create/copy files and use "git add" to track) Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ echo "New data" > data Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch master Initial commit Untracked files: (use "git add <file>..."
to include in what will be committed) data nothing added to commit but untracked files present (use "git add" to track)

git status報告一個未追蹤的檔案。

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ touch main.o

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        data
        main.o

nothing added to commit but untracked files present (use "git add" to track)

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ echo main.o > .gitignore

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git status
On branch master

Initial commit

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        .gitignore
        data

nothing added to commit but untracked files present (use "git add" to track)

[email protected] MINGW32 /d/gittest/my_stuff (master)
$

為了讓Git忽略目錄中的檔案,只需要將該檔名新增到一個特殊的檔案.gitignore中就可以了。

5.3 使用git add
git add命令將暫存一個檔案。
可以使用git ls-files命令檢視隱藏在物件模型下的東西,並且可以找到那些暫存檔案的SHA1值。

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master)
$ git ls-files --stage
100644 0487f44090ad950f61955271cf0a2d6c6a83ad9a 0       .gitignore
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       data

在任何編輯之後,提交變更之前,請執行git add命令,用最新版本的檔案去更新索引。

5.4 使用git commit的一些注意事項
5.4.1 使用git commit –all
git commit的-a或者-all選項會導致執行提交之前自動暫存所有未暫存的和未追蹤的檔案變化,包括從工作副本中刪除已追蹤的檔案。

[email protected] MINGW32 /d/gittest
$ mkdir commit-all-example

[email protected] MINGW32 /d/gittest
$ cd commit-all-example/

[email protected] MINGW32 /d/gittest/commit-all-example
$ git init
Initialized empty Git repository in D:/gittest/commit-all-example/.git/

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ echo something >> ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ echo something else >> notyet

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add readty notyet
fatal: pathspec 'readty' did not match any files

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add ready notyet
warning: LF will be replaced by CRLF in notyet.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in ready.
The file will have its original line endings in your working directory.

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git commit -m "Setup"
[master (root-commit) 599023e] Setup
 2 files changed, 2 insertions(+)
 create mode 100644 notyet
 create mode 100644 ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
nothing to commit, working tree clean

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ vim ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add ready
warning: LF will be replaced by CRLF in ready.
The file will have its original line endings in your working directory.

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ vim notyet

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ mkdir subdir

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ echo Nope >> subdir/new

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   ready

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:   notyet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        subdir/


[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git commit -all
error: did you mean `--all` (with two dashes ?)

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git commit --all
warning: LF will be replaced by CRLF in notyet.
The file will have its original line endings in your working directory.
[master 5b37342] yes
 2 files changed, 2 insertions(+), 2 deletions(-)

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        subdir/

nothing added to commit but untracked files present (use "git add" to track)

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$

5.4.2 編寫提交日誌資訊

5.5 使用rm
git rm命令自然是與git add相反的命令。它會在版本庫與工作目錄中同時刪除檔案。

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ echo "Random stuff" >> cops

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git rm cops
fatal: pathspec 'cops' did not match any files

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add cops
warning: LF will be replaced by CRLF in cops.
The file will have its original line endings in your working directory.

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   cops

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        subdir/


[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git ls-files --stage
100644 fcd87b055f261557434fa9956e6ce29433a5cd1c 0       cops
100644 5daf280806b7c3a07dccbe5e8682cd183fa9382a 0       notyet
100644 6fd96237a0210e56c126124dc8e01ba22638687e 0       ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git rm --cached cops
rm 'cops'

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git ls-files --stage
100644 5daf280806b7c3a07dccbe5e8682cd183fa9382a 0       notyet
100644 6fd96237a0210e56c126124dc8e01ba22638687e 0       ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ ls
cops  notyet  ready  subdir/

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$

git rm –cached會刪除索引中的檔案並把它保留在工作目錄中,而git rm則會將檔案從索引和工作目錄中都刪除。

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ ls
cops  notyet  ready  subdir/

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git rm ready
rm 'ready'

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    ready

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        cops
        subdir/


[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ ls
cops  notyet  subdir/

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add ready
fatal: pathspec 'ready' did not match any files

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git add ready
fatal: pathspec 'ready' did not match any files

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git checkout HEAD -- ready

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ cat ready
something edit

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        cops
        subdir/

nothing added to commit but untracked files present (use "git add" to track)

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$ ls
cops  notyet  ready  subdir/

[email protected] MINGW32 /d/gittest/commit-all-example (master)
$

5.6 使用git mv
移動或者重命令檔案,可以對舊檔案使用git rm命令,然後用git add命令新增新檔案,或者可以直接使用git mv命令。

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git mv data mydata

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   .gitignore
        new file:   mydata


[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git commit -m "Moved data to mydata"
[master (root-commit) db61163] Moved data to mydata
 2 files changed, 1 insertion(+)
 create mode 100644 .gitignore
 create mode 100644 mydata

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git log mydata
commit db61163b9d15f3e2f576cab69c34d614bfa9521a
Author: peter <[email protected]>
Date:   Tue Jul 4 00:01:33 2017 +0800

    Moved data to mydata

[email protected] MINGW32 /d/gittest/my_stuff (master)
$ git log --follow mydata
commit db61163b9d15f3e2f576cab69c34d614bfa9521a
Author: peter <[email protected]>
Date:   Tue Jul 4 00:01:33 2017 +0800

    Moved data to mydata

[email protected] MINGW32 /d/gittest/my_stuff (master)
$

5.7 追蹤重新命名註解

5.8 .gitignore檔案
可以將想要忽略的檔案的檔名加到同一目錄下的.gitignore中即可。此外,可以通過將檔名新增到該版本庫頂層目錄下的.gitignore檔案中來忽略它。
一個.gitignore檔案下可以包含一個檔名模式列表,指定哪些檔案要忽略。

5.9 Git中物件模型和檔案的詳細檢視

相關推薦

5 檔案管理索引

5.1 關於索引的一切 Git的索引不包含任何檔案內容,它僅僅追蹤你需要提交的那些內容。當執行git commit命令的時候,Git會通過檢查索引而不是工作目錄來找到提交的內容。 5.2 Git中的檔案分類 Git將所有檔案分層3類: 已追蹤的

檔案管理(一)——檔案檔案系統

**資料項:**描述物件某種屬性的字符集;是資料組織中可以命名的最小邏輯資料單位。 **記錄:**一組相關資料項集合,描述物件某方面的屬性; **關鍵字:**一個記錄中的一個或幾個資料項的集合,用於唯一的標識一個記錄。 檔案:由建立者定義的、具有檔名的一組相關元素的集合。 有結構:由相關記錄

5 操作架構、索引檢視

一、建立檢視: 1、語法格式: create view 檢視名 as 查詢表示式 with check option 2、新建檢視 在資源管理器中選擇檢視——>右擊新建 二、刪除和修改檢視 1、圖形化介面: alter view 檢視名 as select

5 IP地址子網劃分(2)_IP地址分類NAT技術

sts 端口 主機數 int 2.3 主機ip 主機 和源 找到 3. IP地址的分類 (1)五類IP地址 (2)數軸表示法 4. 保留地址 (1)網段的地址:主機ID全0。如192.168.100.0/24,其中的192.168.10.0指的是網段。 (2)廣播地

5 IP地址子網劃分(4)_超網合並網段

8.0 str ges 分析 需求 由於 子類 log spa 7. 超網合並網段 7.1 合並網段 (1)子網劃分是將一個網絡的主機位當網絡位,來劃分出多個子網。而多個網段合並成一個大網段,合並後的網段稱為超網。 (2)需求分析   某企業有一個網段,該網段有200臺計算

轉載--編寫高質量代碼:改善Java程序的151個建議(5:數組集合___建議65~69)

ceo next foreach遍歷 通過 當前 prev 支持 變量 信息 閱讀目錄 建議65:避開基本類型數組轉換列表陷阱 建議66:asList方法產生的List的對象不可更改 建議67:不同的列表選擇不同的遍歷算法 建議68:頻繁插入和刪除時使用LinkLis

C++ Primer Plus六版編程練習---5 循環關系表達式

AI ++ str eas prim OS ase AS stream 1、 #include <iostream> int main() { int startNum = 0; int endNum = 0; std::cout &

5 選舉模式ZooKeeper的叢集安裝 5-1 叢集的一些基本概念

xx就是我們的master,也就是我們的主節點。心跳機制,當有一個節點掛掉之後,整個叢集還是可以工作的。選舉模式,我們現在的master是正常執行的,但是在某些情況下它宕機了宕機了,那麼這個時候它這個叢集裡面就少了master,沒有master兩個slave需要去競爭。競爭完之後slave1把slave2給幹

5:座標依賴/5.2 座標詳解

座標詳解 座標內容包括 groupid:必選 概念:通用用java包的形式表示(也就是.(點)表示法),內容一般是組織或者公司下的某個專案 例如:org.sonatype.nexus,org.sonatype 為非盈利組織

5:座標依賴/5.9 最佳實踐/5.9.2 依賴屬性使用變數

依賴屬性使用變數 概念:用變數定義依賴的某一部分屬性,具體依賴中直接使用這個依賴即可,這樣做的好處是以後修改這個屬性時只需要修改這個變數即可 語法: 定義變數: <properties> <!—變數名--> <spring

5:座標依賴/5.9 最佳實踐/5.9.1 排除依賴

排除依賴 概念:用於排除某個依賴,比如某個傳遞依賴版本不穩定時,用於排除這個傳遞性依賴;又比如某個傳遞性依賴存在版權問題,而不能放在中央倉庫,所以要進行排除 語法: <exclusions>   <exclusion> <grou

檔案管理

檔案控制塊—FCB 為了能對一個檔案進行正確的存取,必須為檔案設定用於描述和控制檔案的資料結構,稱之為“檔案控制塊”(FCB) 檔案與檔案控制塊一一對應 記錄檔名及其存放地址、檔案的說明和控制資訊。(是誰?在哪裡?什麼權?) 檔案管理程式藉助

5:函式程式碼複用

註明:本系列課程專為全國計算機等級考試二級 Python 語言程式設計考試服務 目錄 考綱考點 知識導圖 1、函式的基本使用 函式的定義 函式的使用 2、函式的引數傳遞 可選引數傳遞 引數名稱傳遞 函式的返回值 3、變數的作用域 區域性變數 全

5 選舉模式ZooKeeper的叢集安裝

選舉模式和ZooKeeper的叢集安裝 5-1 叢集的一些基本概念 5-2 單機偽分散式安裝zookeeper叢集 5-3 三臺物理機(虛擬機器)安裝zookeeper叢集 5-4 測試叢集角色以及選舉 5-1 叢集的一些基本概念

《高效能MySQL》5 建立高效能的索引

5.1 索引基礎 索引是儲存引擎快速找到記錄的一種資料結構,因為在引擎層,所以沒有統一的標準。 如果沒有特別說明,一般的索引指B-Tree索引,InnoDB用的B+樹 不需要全表掃描,而是從索引根節點開始搜尋。 根節點的槽中存放指向子節點的指標。通過

5 概率分析隨機演算法

練習 5.1-1 證明:因為在過程HIRE-ASSISTANT的第4行中,我們總能決定哪一個應聘者最佳,所以我們能比較任意兩個應聘者的好壞,則意味著我們知道應聘者排名的全部次序。 5.2-1 當面試的第一個應聘者是最好的應聘者時,你正好僱用一次。所以你正好僱用一次的概

5:座標依賴/5.9 最佳實踐/5.9.3 依賴關係檢視

依賴關係檢視 檢視依賴列表:mvn dependency:list 概念:查詢某個專案所有的依賴關係,平級顯示 舉例: 不區分依賴關係,全部羅列出來 [INFO]    org.springframework:spring-beans:jar:2.5.6:c

易學筆記--從0開始學JAVA(個人純手工筆記共享 免費!免費!免費!)--5 初始化清理

引數數量 引數型別 過載原則 原始碼: //: HelloDate.java import java.util.*; //import static net.mindview.until.Print.*; /*

檔案管理

裝置控制器的組成 1 裝置控制器與處理機的介面: 資料線 控制線 地址線 2.裝置控制器與裝置的介面:介面中3類訊號為資料,狀態 控制訊號 3. I/o邏輯:主要由指令譯碼器和地址譯碼器兩部分功能部件構成,將CPU的命令和地址分別譯碼, 控制指定裝置進行I/O操作。 裝置控制器的功能? 1.接收和

檔案管理(二)——檔案的邏輯結構

分類有幾種: 1.順序檔案(更適合定長) 兩種記錄排列方式 串結構:按記錄形成的時間順序序列排序。記錄順序與關鍵字無關; 順序結構:按關鍵字排序。 檢索方法: 從頭檢索,順序查詢要找的記錄,定長的計算相對快。 順序結構,可用折半查詢、插值查詢、跳步查詢等演算法提