用git创建和使用 bare 的 git repository 的一个示例

阅读: 评论:0

用git创建和使用 bare 的 git repository 的一个示例

用git创建和使用 bare 的 git repository 的一个示例

一直以来,我都是"git init"之后,就立即使用git仓库了。今天需要为自己的git仓库另外clone到一个地方并修改和提交,然后在提交时发现有如下错误:

zx+Administrator@zx MINGW64 /d/my_work/my_code_clone (master)
$ git push
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 367 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To D:/my_work/my_code_origin/! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'D:/my_work/my_code_origin/'zx+Administrator@zx MINGW64 /d/my_work/my_code_clone (master)
$
然后,我才知道 git repository 有 bare 和 non-bare 之分。我之前创建的都是 non-bare 的。

建立 Git 仓库:

下面是创建和使用 bare 的 git repository 的步骤:

zx+Administrator@zx MINGW64 /e/learn_git
$ git init --bare /e/learn_git/myProject.git
Initialized empty Git repository in E:/learn_git/myProject.git/
注:创建一个bare的仓库。仓库的名字为"myProject"。
注:举例来说,一个叫做 my-project 的裸版本项目应该存储在名为 my-project.git 的目录下。zx+Administrator@zx MINGW64 /e/learn_git
$ git clone /e/learn_git/myProject.git/ /e/learn_git/myProject
Cloning into 'E:/learn_git/myProject'...
warning: You appear to have cloned an empty repository.
done.
注:克隆"/e/learn_git/myProject.git/"到路径"/e/learn_git/myProject"下。
注:一般不指定路径。不指定时,默认克隆到当前路径的 my-project 目录下。zx+Administrator@zx MINGW64 /e/learn_git
$ cd /e/learn_git/myProjectzx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ echo "12345qwert" > 
注:创建一个名为""的文件。zx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git add +Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git commit -am 'add my first file to [myProject] repository.'
[master (root-commit) 4200a1a] add my first file to [myProject] repository.1 file changed, 1 insertion(+)create mode 100644 
注:提交""到本地版本库。zx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git pull --rebase
Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
注:从远程库那里拉取数据。zx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 256 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To E:/learn_git/myProject.git/* [new branch]      master -> master
注:将本地库的更新推送到远程库。zx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git pull --rebase
Current branch master is up +Administrator@zx MINGW64 /e/learn_git/myProject (master)
$ git push
Everything up-to-datezx+Administrator@zx MINGW64 /e/learn_git/myProject (master)
$
完。

本文发布于:2024-02-03 01:01:45,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170689333347634.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:示例   git   bare   repository
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23