您现在的位置是:首页 >技术交流 >关于创建git 仓库的一些问题网站首页技术交流
关于创建git 仓库的一些问题
给android stdio 配置一个git仓库多人开发
一定要创建一个分支例如 caron
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git init
Initialized empty Git repository in /home/wuyu/wuyu_share/android_stdio_project_git/kunpengApp/.git/
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ touch readme
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git add .
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git commit -m "readme"
[master (root-commit) a58d3e7] readme
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git log
commit a58d3e7abf592c708b622ba8966db11319562c1b (HEAD -> master)
Author: wuyu <wuyu@caron-tech.com>
Date: Wed Jun 7 17:23:14 2023 +0800
readme
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git branch caron
wuyu@ubuntu:~/wuyu_share/android_stdio_project_git/kunpengApp$ git branch
caron
* master
git init 和git –bare init 的具体区别?
一般个人使用,用git init,这时候你的工作区也在这里。你要是想建立一个固定的地址让大家一起用,就在服务器上用git –bare init。
其实你可以看到,init建立的.git目录内容和–bare建立的目录内容是差不多的。
在初始化远程仓库时最好使用 git –bare init 而不要使用:git init。这样在使用hooks的时候,会有用处。
如果使用了git init初始化,则远程仓库的目录下,也包含work tree,当本地仓库向远程仓库push时, 如果远程仓库正在push的分支上(如果当时不在push的分支,就没有问题,在同一分支要添加git config receive.denyCurrentBranch warn), 那么push后的结果不会反应在work tree上, 也即在远程仓库的目录下对应的文件还是之前的内容,必须得使用git reset –hard才能看到push后的内容.
问题:
开发机提交代码到远程仓库时,出错如下错误:
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 304 bytes | 152.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/caron
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To \192.168.1.183\wuyu_share\android_stdio_project_git\kunpengApp\.git
! [remote rejected] caron -> caron (branch is currently checked out)
error: failed to push some refs to '\192.168.1.183\wuyu_share\android_stdio_project_git\kunpengApp\.git'
解决办法:
在服务器端仓库目录下
$ cd /kunpengApp/.git
$ git config receive.denyCurrentBranch warn