Repository files navigation
在地端創建一個資料夾gitA 扮演協作者A, 資料夾內新增hello.txt
hello.txt內容為 "hello git"
打開terminal 使用 git --version可以確認git是否成功安裝git和查看版本
terminal輸入cd gitA 進入gitA資料夾為根目錄
輸入git init 初始化資料夾
使用 git add .追蹤資料夾內檔案
使用 git commit -m "add hello file" 存檔進度並新增description
使用 git status 可以查看狀態
使用 git log查看respository local端的版本紀錄
協作者A 將地端repository 傳到 github
到github建立 new repository (public or private) 取名:git-practice
選擇push an existing repository from the command line 複製指令貼上terminal
回到github重整可看到gitA的資料已經push到github上
在地端建立一個新資料夾gitB 扮演協作者B
確認terminal位置在gitB資料夾根目錄內
先git init
去github repository:git-practice複製url
回gitB terminal 打git clone [url]
此時可以看到原本空的gitB資料夾裡面已經有一個叫git-practice的資料夾裡面包含hello.txt
協作者A : git branch A建立A分支, git switch A切換到A分支
協作者B : 要先cd切換到git-practice資料夾, 再git branch B建立B分支, git switch B切換到B分支
協作者A : 編輯hello.txt, 加上 "I am A"
協作者B : 編輯hello.txt, 加上 "I am B"
協作者A : git add ., git commit -m "add A", git push -u origin A, 可以看到github上已經有分支A和hello.txt(A ver)
協作者B : git add . ,git commit -m "add B", git push -u origin B, 可以看到github上已經有分支B和hello.txt(B ver)
回到協作者A的terminal, git switch main回到主分支, git merge A(此時會發現vs code上方工作區會出現第二行"I am A")
不用add, commit 直接git push (因為存檔點和分支A一樣, 所以不用再存一次), 此時github上main裡面的檔案已經有"I am A"了
回到協作者B的terminal, git switch main回到主分支, git checkout,git pull, 把最新版本的main內容拉下來
git merge B會發生衝突, 選擇accept both
因為是新的內容所以要 git add ., git commit -m "merge A and B", git push
此時github上main分支有A+B, A分支只有I am A, B分支只有I am B
切換到各自的branch, git pull origin main
各自 add, commit, push
此時github上 main, A, B都是A+B的最新版本
取消add: git reset <file> 或是 git rerset
git add 全部除了特定folder或檔案: git add -- . ':!<path>'
About
專案管理- git 協作練習
Resources
Stars
Watchers
Forks
You can’t perform that action at this time.