我使用git init --bare在linux上创建一个裸存储库,但是我想同时设置其源目录位置,因此尽管裸存储库仅保存git commit记录,但我可以直接在linux。找到源代码。
答案 0 :(得分:0)
裸仓库没有默认的工作树,但是您可以添加一个或多个。
如果您从头开始创建裸仓库,那么它还没有任何提交。您需要从另一个存储库中推送提交,或者在裸仓库中创建至少一个提交。
# 1. push from another repository "bar"
cd /path/to/bar
git push /path/to/foo master
# add a worktree for "master"
cd /path/to/foo
git worktree add /path/to/worktree master
# ------------------------------------------------
# 2. create commit from the bare repository "foo"
cd /path/to/foo
# create the empty tree
tree=$(git hash-object -w -t tree --stdin < /dev/null)
# create a commit from the tree
commit=$(git commit-tree -m "initial commit" $tree)
# create "master" from the commit
git update-ref refs/heads/master $commit
# add a worktree for "master"
git worktree add /path/to/worktree master
但是现在,如果克隆/path/to/foo
并进行提交,然后将master
推回到/path/to/foo
,则工作树/path/to/worktree
中的状态将有些奇怪。您需要在git reset --hard
中运行/path/to/worktree
来更新其状态和代码。
除了工作树之外,您还可以从/path/to/foo
进行克隆。
git clone /path/to/foo worktree
cd worktree
# checkout branch "master", which should be already checked out by default
git checkout master
# update "master"
git pull origin master
# update other branches
git fetch
# checkout a new branch "dev" which has been pushed to /path/to/foo
git checkout dev