git - 创建 git init --bare 时如何设置源目录的存储目录?
问题描述
我在linux上使用git init --bare创建了一个裸仓库,但是我想同时设置它的源目录位置,这样虽然裸仓库只保存了git提交记录,但是我可以直接在linux上做。找到源代码。
解决方案
裸仓库没有默认工作树,但您可以添加一个或任意多个。
如果你从头开始创建一个裸仓库,它还没有任何提交。您需要从另一个存储库推送提交或在裸存储库中创建至少一个。
# 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
推荐阅读
- python - 通过 pandas 合并或 SQL JOIN 查询将 sqlite 中的 NULL 替换为另一个表中的值
- r - R - lapply - 从列表中获取数据帧?
- sql-server - 在这种情况下如何在 T-SQL 中进行 GROUP BY
- vue.js - VueJS2:避免直接改变一个道具,因为每当父组件重新渲染时,该值都会被覆盖
- python - 分组时我无法对值进行排序
- ruby - Cucumber:我想在我的所有场景都执行后通过电子邮件发送报告,有没有可以在 hooks.rb 中使用的类似“AfterAll”的方法
- powershell - Powershell 命令仅在导入 CSV 时有效 - 365
- python - AWS cloud9 pip install 转到 python 2.7 而不是 3.6
- python - python向量在大小为5的块中跨轴应用平均值
- java - Java Spring Boot中的Mongo Repository findById不起作用