git add main.texgit commit -m "Add a line from Git"git push
輸出的最後一行會顯示移動的分支:
53aca61..db007e3 main -> main
變更會出現在編輯器中,已開啟的編輯器會自動更新。新檔案、資料夾與重新命名會顯示在檔案樹中。在 History 中,您的變更會標示為 You (via Git)。那裡不會顯示您的提交訊息。
專案歷程中的一次推送
如果 Git 拒絕您的推送
如果專案在這段期間有所變更,Git 會拒絕推送:
! [rejected] main -> main (fetch first)
請先取得這些變更,然後再次推送:
git pull --no-rebase --no-editgit push
單純的 git pull 可能會以 fatal: Need to specify how to reconcile divergent branches. 停止。上方的 --no-rebase 選項就是為此而設:它會合併兩邊的變更。如果兩邊修改了相同的行,pull 會以 CONFLICT (content): Merge conflict in main.tex 停止。修正檔案,然後執行:
git add main.texgit commit -m "Merge the changes from the editor"git push
網站不接受以下兩種情況:
其他分支:! [remote rejected] feature -> feature (wrong branch)。只有 main 分支,因此請將您的工作推送到那裡。
強制推送:! [remote rejected] main -> main (forced push prohibited)。請改為將您的變更放在目前的 main 之上。
如果 Git 顯示 Authentication failed
remote: Enter your Git authentication token when prompted for a password.fatal: Authentication failed for 'https://<your-site>/git/<project-id>/'