Git

Git

———-基礎———-

設定登入資訊 git config –global user.name ‘你的名字’ git config –global user.email ‘你的Email’

列出有異動的檔案 git clone https://XXX.com.tw/backweb.git ‘test/backweb’ git -C ‘test/backweb’ status –porcelain git -C ‘test/backweb’ fetch git -C ‘test/backweb’ pull

git clone –filter=blob:none –no-checkout $remoteGit_Url/$childFolderName.git ‘$sparseCheckoutFolderDir/$childFolderName’

git -C ‘test/backweb’ sparse-checkout init –cone git -C ‘test/backweb’ sparse-checkout set doc/ git -C ‘test/backweb’ switch master

(-C 後面接相對路徑)

設定config

git config –global user.email ‘shilvain@XXX.com.tw’ git config –global user.name ‘Shilvain’

遠端還沒有分支的時候,第一次對分支做push,要加上-u git push -u origin feature/somebranch

———-將變更狀態結果更容易讓程式判讀———-

git status –porcelain

———-從develop分支切一個新分支———-

git switch develop

git checkout -b feature/somebranch

———-第一次從遠端拉分支道地端———-

git switch -c uat –track origin/uat

———-取消merge———-

適用情形: 1.merge發生衝突 2.merge 成功但 尚未 git commit

git merge –abort

備註: 回到 merge 之前的狀態 工作目錄、HEAD 都會還原

———-確認Branch 對到哪個遠端Branch———-

git branch -vv

———-設定Branch 對到遠端Branch———-

git branch –set-upstream-to=origin/dev

———-git add 之後,想從add list 移除特定檔案———-

git restore –staged [檔案名稱(含副檔名)]

———-取消 git commit (回到上一個commit狀態)———-

git reset –soft HEAD~1

HEAD~1:代表最後一次 commit –soft:保留檔案變更在 staged(ready to commit)狀態

連 staged 也取消,變成 unstaged git reset HEAD~1

———-設定branch track remote branch———-

git branch –set-upstream-to=origin/develop

———-Git Remote———- 新增 git remote set-url add origin https://xxx.aaaa.git

取代原本 git remote set-url origin https://xxx.aaaa.git

刪除 git remote rm origin

Git Sparse Checkout———-

Clone Git 結構

git clone –filter=blob:none –no-checkout http://192.168.1.130:3000/gituser/TestWeb.git

Sparse 初始化

git sparse-checkout init –cone

#設定Sparse目錄 git sparse-checkout set docs git sparse-checkout set docs/internal docs/external

4️⃣ 保留原設定多檢出 docs/external 目錄

git sparse-checkout add docs/external

拉特定資料

git checkout HEAD git switch master

清空 sparse-checkout 設定

git sparse-checkout set –no-cone

#刪除/sparse-checkout 檔案 rm -force .git/info/sparse-checkout

查看目前被設定檢出的資料夾 git sparse-checkout list

#完全退出sparse模式 git sparse-checkout disable

2️⃣ 手動確保設定已關閉

git config core.sparseCheckout false

3️⃣ 重新展開完整目錄

git read-tree -mu HEAD

標籤: git, 版本控制