使用 git clone
时,有一个选项 -n
可以防止在克隆存储库后签出 HEAD
。有可能手动执行此操作吗?
编辑我认为选项-n
在手册中读起来比实际情况更好:使用-n
克隆后,我的所有工具都显示我仍然驻留在主分支上;唯一的区别是所有文件都显示为已删除。这与我所说的“未签出”实际上并不相同。
那么也许我应该删除 HEAD
?
With git clone
there is the option -n
wich prevents a checkout of HEAD
after the repository is cloned. Is there a possibility to do this manually?
Edit I think the option -n
reads better in the manual than it actually is: After cloning with -n
all my tools show that I still reside on the master branch; the only difference being that all files are shown as deleted. It’s not really the same situation that I would call ‘not checked out’.
So maybe I should just delete HEAD
?
发布评论
评论(2)
最简单的解决方案是将其克隆为裸:(
并删除您签出的存储库)
基本上,您需要将存储库转换为裸存储库,根据 这个问题,可以手动完成:
另请参阅Git:将普通存储库转换为裸存储库,如MikeSep 在评论中。
如果您需要取消签出,请将
bare
保留为false
,然后删除除.git
之外的所有内容。这应该类似于 git clone -n 。The simplest solution would be to clone it bare:
(and delete your checked out repo)
Basically, you need to transform your repo into a bare one, which, according to this question, could be done manually with:
See also Git: Convert normal to bare repository, as mentioned by MikeSep in the comments.
If you need to uncheckout, keep
bare
tofalse
, and simply remove everything but the.git
. That should be like agit clone -n
.我读到最初的问题是想保留存储库,但删除工作树。当您在完成一些工作后想要将项目搁置时,这非常有用。
一种解决方案是创建一个具有空工作树的分支,并签出该空分支:
说明:
git checkout --orphan archived
创建具有不相关历史记录的分支archived
到项目。git commit -m "Project is archived" --allow-empty
创建一个在archived
分支上没有文件的提交。与 git clone -n 选项不同,此方法:
archived
”,因此“archived”存储库已准备好由
git checkout master
重新激活,并且随后可以使用 <代码>git checkout 存档I read the original question as wanting to preserve the repo, but delete the working tree. This is useful when you want to put a project on the backburner, after some work has been done with it.
One solution is to create a branch with an empty working tree, and check out the empty branch:
Explanation:
git checkout --orphan archived
creates the brancharchived
, with unrelated history to the project.git reset --hard
removes versioned files that exist in the working tree. It preserves unversioned files, which can be cleaned out withgit clean -fd
if necessary.git commit -m "Project is archived" --allow-empty
creates a commit with no files on thearchived
branch.Unlike the
git clone -n
option, this method:archived
"A repo thusly 'archived' is ready to be re-activated by
git checkout master
, and can subsequently be re-archived withgit checkout archived