[Git]fatal: You are not currently on a branch.
问题:
执行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了