有没有 git uncheckout ?

发布于 2024-08-23 05:42:58 字数 281 浏览 7 评论 0 原文

使用 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹雪碎 2024-08-30 05:42:58

最简单的解决方案是将其克隆为裸:(

git clone --bare your_repo bare_repo

并删除您签出的存储库)

基本上,您需要将存储库转换为裸存储库,根据 这个问题,可以手动完成:

  • .git/config 文件更改为 bare = true 而不是 bare = false
  • 删除 your_repo/* 中除 .git 文件以外的内容
  • .git 目录内容移至 your_repo/ 并删除 .git 目录

另请参阅Git:将普通存储库转换为裸存储库,如MikeSep 在评论中。

如果您需要取消签出,请将 bare 保留为 false,然后删除除 .git 之外的所有内容。这应该类似于 git clone -n​​ 。

The simplest solution would be to clone it bare:

git clone --bare your_repo bare_repo

(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:

  • changing the .git/config file to have bare = true instead of bare = false
  • removing the contents of your_repo/* other than the .git file
  • moving the .git dir contents into your_repo/ and removing the .git dir

See also Git: Convert normal to bare repository, as mentioned by MikeSep in the comments.

If you need to uncheckout, keep bare to false, and simply remove everything but the .git. That should be like a git clone -n.

云巢 2024-08-30 05:42:58

我读到最初的问题是想保留存储库,但删除工作树。当您在完成一些工作后想要将项目搁置时,这非常有用。

一种解决方案是创建一个具有空工作树的分支,并签出该空分支:

git checkout --orphan archived
git reset --hard
git commit -m "Project is archived" --allow-empty

说明:

  1. git checkout --orphan archived 创建具有不相关历史记录的分支 archived到项目。
  2. git reset --hard 删除工作树中存在的版本化文件。它保留未版本化的文件,如有必要,可以使用 git clean -fd 清除这些文件。
  3. 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:

git checkout --orphan archived
git reset --hard
git commit -m "Project is archived" --allow-empty

Explanation:

  1. git checkout --orphan archived creates the branch archived, with unrelated history to the project.
  2. git reset --hard removes versioned files that exist in the working tree. It preserves unversioned files, which can be cleaned out with git clean -fd if necessary.
  3. git commit -m "Project is archived" --allow-empty creates a commit with no files on the archived branch.

Unlike the git clone -n option, this method:

  • does not leave the index showing all files as "deleted"
  • unambiguously documents what happened to the work tree. The current branch name will be "archived"

A repo thusly 'archived' is ready to be re-activated by git checkout master, and can subsequently be re-archived with git checkout archived

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文