【发布时间】:2022-01-13 18:31:00
【问题描述】:
最终,到目前为止,我想要一种干净的方式来返回紧凑的(例如裸机)存储库,以便随时检查(好吧,对于迂腐的:在附加 core.bare false 之后)到任何分支。我已经阅读了How to convert a normal Git repository to a bare one? 的热门答案。使用 clone 会丢失 cmets 中提到的配置条目,下面是尝试使用接受的答案后的问题。也许有一个简单的微不足道的解决方法,这就是为什么我在 cmets 中找不到它。
TL;DR
我正在尝试理解与裸 git repos 相关的信息。
执行并成功:
git clone --mirror https://github.com/vmatare/thinkfan.git path/to/dest/.git
cd path/to/dest
git config --bool core.bare false
git checkout master # checkout devel also works with freshly cloned repo
Man git-clone:
--mirror Set up a mirror of the source repository. This implies --bare. Compared to --bare, --mirror not only maps local branches of the source to local branches of the target, it maps all refs (including remote-tracking branches, notes etc.) and sets up a refspec configuration such that all these refs are overwritten by a git remote update in the target repository.
现在在git checkout anybranch 之前,我只有.git 文件夹和:
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
...
“已删除”输出为绿色。也就是说,删除在索引中并准备好提交(根据输出并在https://unix.stackexchange.com/questions/458354/git-status-coloring-deleted-files 中解释)。
执行:
cd repo
mv .git ../repo.git # renaming just for clarity
cd ..
rm -fr repo
cd repo.git
git config --bool core.bare true
即删除除.git 之外的所有内容并将core.bare 配置值更改为true。
之后
git config --bool core.bare false
顺便说一句
git config --bool core.bare true
git config --bool core.bare false
等于没有或某些内部状态发生了变化?无论如何,两者都意味着我遵循了被接受的赞成答案来制作裸回购。并且做clone --mirror 我也做了裸回购。但是现在“deleted”是红色的,输出是“Changes not staged for commit”:
git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
...
no changes added to commit (use "git add" and/or "git commit -a")
为什么原来克隆的repo和再转bare有这么大的区别?
我已尝试阅读 cmets 的答案以制作裸仓库,但没有注意到提及该问题。
如果现在我做git add *,那么显然状态会变得和我刚用--mirror克隆时一样:
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
deleted: .github/workflows/ccpp.yml
deleted: CMakeLists.txt
deleted: COPYING
deleted: README.md
但是在比之后结帐不起作用。
$ git checkout devel
error: Your local changes to the following files would be overwritten by checkout:
CMakeLists.txt
Please commit your changes or stash them before you switch branches.
Aborting
如何在clone --mirror 之后和删除除.git 之外的所有内容之后查看repo "status" 之间的区别,看看为什么checkout 在第一种情况下有效,而在第二种情况下无效?
【问题讨论】:
标签: git version-control