Git常用配置
git初始化
git初始化有两种模式,一种是git init 这种模式会记录当前库提交的版本以及显示项目文件,一种是git init --bare,称为裸仓库,当前仓库是无法提交的,因为不包含项目文件,只包含版本库,因此这种模式多用于远程仓库的核心仓库(很像SVN中的中央仓库)
如果远程库是一个git init库,则在第一次push到远程库时会提示'receive.denyCurrentBranch' Configuration variable to 'refuse',即拒绝合并到当前分支,需进行如下配置:git config receive.denyCurrentBranch=ignore即可。push成功后,还需要在远程库执行git reset --hard,回滚到最新的提交历史才可以显示最新的提交
所以强烈建议先使用git init --bare设置个中央远程库,再从中央远程库拉取
还有就是push失败很有可能是权限问题,git用户没有创建目录的权限,所以需要在服务器上授权,要么修改拥有者或组,要么修改权限
Git常遇问题
问题:git push或git pull的时出现如下错误:
$ 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>
说明:根据上面的提示,直接git push origin master实际并不能解决问题
或
$ git pull
You are not currently on a branch, so I cannot use any
'branch.<branchname>.merge' in your configuration file.
Please specify which remote branch you want to use on the command
line and try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
解决方案:
第一步:git checkout -b temp 切换到一个临时的分支
第二步:git checkout master 再切换回主分支
就可以恢复到master repository的状态,然后就可以push和pull了