Download - 20150313 ian git

Transcript
Page 1: 20150313 ian git
Page 2: 20150313 ian git

Git介紹

有效率的處理大型專案

分散式開發模型

支援非線性的開發

定期的封裝物件

歷史紀錄保護

Page 3: 20150313 ian git

Git tool for windows

Git for Windows

GitHub for Windows

SourceTree

Page 4: 20150313 ian git

Git常用指令

使用 Git Shell建立 local repository

git init

用 GitHub建立 remote repository

git clone [repository url]

Page 5: 20150313 ian git

將新增的檔案加入到 Git版本控管

git add .

重設工作目錄的索引狀態

git reset

查詢狀態

git status

Page 6: 20150313 ian git

提交變更/建立版本

git commit

git commit –m “說明文字”

查詢歷史記錄

git log [-log size]

Page 7: 20150313 ian git

刪除檔案

git rm fileName

檔案更名

git mv oldName NewName

Page 8: 20150313 ian git

Reset current working directory

git reset --hard

Undo file

git checkout master “fileName”

Page 9: 20150313 ian git

Git status

Page 10: 20150313 ian git

Git status

Page 11: 20150313 ian git

git status

Changes to be committed (準備提交的變更)

Changes not staged for commit (尚未準備提交的變更)

Untracked files (未追蹤的變更)

PS.在 .gitignore檔案中列出的檔案名稱將被忽略(.gitignore這個檔也要commit!)

Page 12: 20150313 ian git

Object

將一個檔案的內容中取出,透過內容產生一組 SHA1

雜湊值,然後依照這個 SHA1 雜湊值命名的一個檔案。

所有要進行控管的目錄與檔案,都會先區分「目錄資訊」(tree object)與「檔案內容」(blob object)並存於「物件儲存區」 (object storage)

Page 13: 20150313 ian git

Object

blob 物件:就是工作目錄中某個檔案的 “內容”,且只有內容而已,檔名則是物件內容的雜湊運算結果,沒有任何其他其他資訊。

tree 物件:這類物件會儲存特定目錄下的所有資訊,包含該目錄下的檔名、對應的 blob 物件名稱、檔案連結(symbolic link) 或其他 tree 物件等等。由於 tree 物件可以包含其他 tree 物件,所以瀏覽 tree 物件的方式其實就跟檔案系統中的「資料夾」沒兩樣。

Page 14: 20150313 ian git

Object

commit 物件:用來記錄有那些 tree 物件包含在版本中,一個 commit 物件代表著 Git的一次提交,記錄著特定提交版本有哪些 tree 物件、以及版本提交的時間、紀錄訊息等等。

tag 物件:是一個容器,通常用來關聯特定一個 commit 物件 (也可以關聯到特定 blob、tree 物件),並額外儲存一些額外的參考資訊(metadata),例如: tag 名稱。使用 tag 物件最常見的情況是替特定一個版本的 commit 物件標示一個易懂的名稱,可能是代表某個特定發行的版本,或是擁有某個特殊意義的版本。

Page 15: 20150313 ian git

Index

常位於 .git目錄下的一位名為 index 的檔案

紀錄「有哪些檔案即將要被提交到下一個 commit 版本中」

Page 16: 20150313 ian git

觀念

要使用 Git版本控管,你必須先建立「Working directory」與「Repository」。(mkdir, git init)

在「Working directory」進行開發,你可能會建立目錄、建立檔案、修改檔案、刪除檔案、... 等操作。

然後當你想提交一個新版本到 Git的「Repository」裡,一定要先更新「index」狀態。(git add, git mv, ...)

然後 Git會依據「索index」當下的狀態,決定要把那些檔案提交到 Git的「Repository」裡。(git status)

最後提交變更時 (git commit),才會把版本資訊寫入到「物件儲存區」當中 (此時將會寫入 commit 物件)。

Page 17: 20150313 ian git

Branch

git branch

git branch [branch_name]

git checkout -b [branch_name]

git checkout [branch_name]

git branch -d [branch_name]

Page 18: 20150313 ian git

Pull

Pull -從遠端更新

git pull 或 git pull origin master

實際作用是先 git fetch 遠端的 branch,然後與本地端的 branch 做 merge,產生一個 merge commit 節點

Page 19: 20150313 ian git

Push

Push -將 Commit 送出去

git push 或 git push origin master

實際的作用是將本地端的 master branch 與遠端的master branch 作 fast-forward 合併。如果出現[rejected] 錯誤的話,表示你必須先作 pull。

Page 20: 20150313 ian git

Reference

https://github.com/doggy8088/Learn-Git-in-30-days

http://oolab.csie.ncu.edu.tw/wiki/images/e/e7/Giteveryone-

101022053442-phpapp02.pdf

http://dylandy.github.io/Easy-Git-Tutorial/index.html


Top Related