不熟悉 Git 指令列者建議先使用圖形化工具(如 TortoiseGit)。以下為指令列操作的標準流程與衝突處理實例。
git clone git@192.168.10.202:develop/test.git cd test touch test.txt git add test.txt git commit -m 'test' git push # 若報錯:需指定分支 git push origin master # 首次推送指定上游分支,之後可直接 git push
新增目錄操作相同。
echo "11111111111" > test.txt git add test.txt && git commit -m 'test2' git push
echo "abc" > test.txt git commit -am "test3" # -a 自動暫存所有已追蹤檔案的修改 git push
git commit -a # 進入編輯器,保留需提交的檔案行(移除前面 #),存檔離開 git push
git rm ab # 刪除檔案 git rm -r dirname # 刪除目錄加 -r git commit -am "del" git push
git push # 錯誤:rejected non-fast-forward git pull # 提示 CONFLICT (content): Merge conflict in test.txt vim test.txt # 手動解決衝突標記(<<<<<<<, =======, >>>>>>>) git commit -am "remove conflict" git push
關鍵點:衝突發生時必須先 git pull 合併遠端變更,解決衝突後再 commit 和 push。