問題:
執行git push 命令之后報錯:
bogon:PPAutoPackageScript usrname$ git commit -m "add test.sh" [detached HEAD da19d347] add test.sh
1 file changed, 4 insertions(+) create mode 100755 xxxxWorkspace/xxxxAPP/PPAutoPackageScript/test.sh bogon:PPAutoPackageScript usrname$ git push fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use git push origin HEAD:<name-of-remote-branch>
這個錯誤從字面上看是,沒有在1個分支上
通過命令 git branch 查看一下,確實沒有
bogon:PPAutoPackageScript usrname$ git branch * (HEAD detached from bdcfe3d8)
解決辦法:
通過git checkout <branchName>切換到1個已經存在的分支上
注意:執行這一步之前,如果你已經修改了文件,記得要先備份你修改的內容,否則切換分支之后,效果等同於重新git了一次代碼,你的修改會被覆蓋掉的
bogon:PPAutoPackageScript usrname$ git checkout develop Warning: you are leaving 1 commit behind, not connected to any of your branches: da19d347 add test.sh If you want to keep it by creating a new branch, this may be a good time to do so with: git branch <new-branch-name> da19d347 Branch 'develop' set up to track remote branch 'develop' from 'origin'. Switched to a new branch 'develop'
再次查看本地倉庫所在分支,已經切換到develop分支了
bogon:PPAutoPackageScript usrname$ git branch * develop
再重新修改文件,就可以成功push了