日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第5章 文件管理和索引

發(fā)布時間:2023/12/16 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第5章 文件管理和索引 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

5.1 關于索引的一切
Git的索引不包含任何文件內(nèi)容,它僅僅追蹤你需要提交的那些內(nèi)容。當執(zhí)行git commit命令的時候,Git會通過檢查索引而不是工作目錄來找到提交的內(nèi)容。

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

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest $ mkdir my_stuffAdministrator@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 masterInitial commitnothing to commit (create/copy files and use "git add" to track)Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ echo "New data" > dataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch masterInitial commitUntracked files:(use "git add <file>..." to include in what will be committed)datanothing added to commit but untracked files present (use "git add" to track)

git status報告一個未追蹤的文件。

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ touch main.oAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch masterInitial commitUntracked files:(use "git add <file>..." to include in what will be committed)datamain.onothing added to commit but untracked files present (use "git add" to track)Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ echo main.o > .gitignoreAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch masterInitial commitUntracked files:(use "git add <file>..." to include in what will be committed).gitignoredatanothing added to commit but untracked files present (use "git add" to track)Administrator@BGUJ9QLXIRFWC3S 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

在任何編輯之后,提交變更之前,請執(zhí)行git add命令,用最新版本的文件去更新索引。

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

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest $ mkdir commit-all-exampleAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest $ cd commit-all-example/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example $ git init Initialized empty Git repository in D:/gittest/commit-all-example/.git/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ echo something >> readyAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ echo something else >> notyetAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git add readty notyet fatal: pathspec 'readty' did not match any filesAdministrator@BGUJ9QLXIRFWC3S 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.Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git commit -m "Setup" [master (root-commit) 599023e] Setup2 files changed, 2 insertions(+)create mode 100644 notyetcreate mode 100644 readyAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git status On branch master nothing to commit, working tree cleanAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ vim readyAdministrator@BGUJ9QLXIRFWC3S 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.Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ vim notyetAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ mkdir subdirAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ echo Nope >> subdir/newAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git status On branch master Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified: readyChanges 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: notyetUntracked files:(use "git add <file>..." to include in what will be committed)subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git commit -all error: did you mean `--all` (with two dashes ?)Administrator@BGUJ9QLXIRFWC3S 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] yes2 files changed, 2 insertions(+), 2 deletions(-)Administrator@BGUJ9QLXIRFWC3S 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)Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $

5.4.2 編寫提交日志信息

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

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ echo "Random stuff" >> copsAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git rm cops fatal: pathspec 'cops' did not match any filesAdministrator@BGUJ9QLXIRFWC3S 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.Administrator@BGUJ9QLXIRFWC3S 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: copsUntracked files:(use "git add <file>..." to include in what will be committed)subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git ls-files --stage 100644 fcd87b055f261557434fa9956e6ce29433a5cd1c 0 cops 100644 5daf280806b7c3a07dccbe5e8682cd183fa9382a 0 notyet 100644 6fd96237a0210e56c126124dc8e01ba22638687e 0 readyAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git rm --cached cops rm 'cops'Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git ls-files --stage 100644 5daf280806b7c3a07dccbe5e8682cd183fa9382a 0 notyet 100644 6fd96237a0210e56c126124dc8e01ba22638687e 0 readyAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ ls cops notyet ready subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $

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

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ ls cops notyet ready subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git rm ready rm 'ready'Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git status On branch master Changes to be committed:(use "git reset HEAD <file>..." to unstage)deleted: readyUntracked files:(use "git add <file>..." to include in what will be committed)copssubdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ ls cops notyet subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git add ready fatal: pathspec 'ready' did not match any filesAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git add ready fatal: pathspec 'ready' did not match any filesAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ git checkout HEAD -- readyAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ cat ready something editAdministrator@BGUJ9QLXIRFWC3S 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)copssubdir/nothing added to commit but untracked files present (use "git add" to track)Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $ ls cops notyet ready subdir/Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/commit-all-example (master) $

5.6 使用git mv
移動或者重命令文件,可以對舊文件使用git rm命令,然后用git add命令添加新文件,或者可以直接使用git mv命令。

Administrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git mv data mydataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git status On branch masterInitial commitChanges to be committed:(use "git rm --cached <file>..." to unstage)new file: .gitignorenew file: mydataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git commit -m "Moved data to mydata" [master (root-commit) db61163] Moved data to mydata2 files changed, 1 insertion(+)create mode 100644 .gitignorecreate mode 100644 mydataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git log mydata commit db61163b9d15f3e2f576cab69c34d614bfa9521a Author: peter <tuziyuxi@gmail.com> Date: Tue Jul 4 00:01:33 2017 +0800Moved data to mydataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $ git log --follow mydata commit db61163b9d15f3e2f576cab69c34d614bfa9521a Author: peter <tuziyuxi@gmail.com> Date: Tue Jul 4 00:01:33 2017 +0800Moved data to mydataAdministrator@BGUJ9QLXIRFWC3S MINGW32 /d/gittest/my_stuff (master) $

5.7 追蹤重命名注解

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

5.9 Git中對象模型和文件的詳細視圖

總結(jié)

以上是生活随笔為你收集整理的第5章 文件管理和索引的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。