Git 學習筆記

2021-08-17 13:27:59 字數 2149 閱讀 5026

git中的檔案內容(blob)均是以hash值來儲存的,每個內容將生成乙個object.同樣的內容則會生成相同的hash值

cat-file -t命令可以讓 git 返回任何物件的型別:

$ git cat-file -t 1f7a7a472abf3dd9643fd615f6da379c4acb3e3ablo

git add

修改過後的檔案要以add命令來推入修改並用git status來檢視檔案狀態

現在我們來修改一下1.py而未經add來看看狀態有什麼改變

test

git:(master)echo test > 1.py

test

git:(master)git status

on branch master

no commits yet

changes to be committed:

(use "git rm --cached ..." to unstage)

new file:   1.py

new file:   1.txt

changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working directory)

modified:   1.py

untracked files:

(use "git add ..." to include in what will be committed)

readme

再建立乙個檔案新readme 檔案而未經過git add

git status

on branch master

no commits yet

changes to be committed:

(use "git rm --cached ..." to unstage)

new file:   1.py

new file:   1.txt

untracked files:

(use "git add ..." to include in what will be committed)

readme

經過add的檔案用git commit命令來提交本地庫

之後會生成2個關於commit的object

test

git:(master)git cat-file -p 8d2a2200237c6a6480a053cd460546603303e68a 

100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 1.py

100644 blob cdbb2ce4ae5b3765b0d33a1acbff426c258b4bcd 1.txt

100644 blob 8178c76d627cade75005b40711b92f4177bc6cfc readme

test

git:(master)git cat-file -p 7ffec2a505a1f366504f9418c2d26f817c8dadbb 

tree 8d2a2200237c6a6480a053cd460546603303e68a

author hello 1521938061 +1100

committer hello 1521938061 +1100

first commit

Git學習筆記

git stash git stash list 顯示git棧內的所有備份,可以利用這個列表來決定從那個地方恢復。git stash clear 清空git棧。此時使用gitg等圖形化工具會發現,原來stash的哪些節點都消失了。關於git stash的詳細解釋,適用場合,這裡做乙個說明 使用git...

git 學習筆記

1 git checkout master 切換分支 2 git checkout b xx 新建分支,同時切換到該分支 3 dev 4 git add a 將變動檔案,提交到index 5 git commit m 將 暫存區 檔案,加入到版本控制中。6 git checkout master 7...

Git 學習筆記

顯示版本庫.git所在的目錄 git rev parse git dir 顯示工作區的根目錄 git rev parse show toplevel 相對於工作區根目錄的相對目錄 git rev parse show prefix git config 命令各引數的區別 git config e 版...