在 Git 中签出早期标签以用于只读目的的最简洁方法

发布于 2024-09-28 16:35:05 字数 376 浏览 12 评论 0原文

我的本地计算机上有一个工作树,还有一个远程存储库。假设我想在已知标签上快速构建项目的早期版本,而不影响工作版本的当前状态。我的倾向是签出一个单独的树,这似乎像这个问题一样:

使用 Git 下载特定标签

从远程存储库进行克隆,然后在其中签出。但克隆做了很多工作并拉下了所有修订状态。有没有一种轻量级的方式来表达“在这个提交/标签处获取世界的当前状态并将其喷射到这个目录中?” (不需要进一步的修订控制——就 Git 而言,它是“只读”的。)

也许不需要——只是检查。

谢谢。

I have a working tree on my local machine, and a remote repository as well. Let's say I want to quickly build an earlier version of my project at a known tag without disturbing the current state of the working version. My inclination is to checkout a separate tree, which seems to go like in this question:

Download a specific tag with Git

With a clone from the remote repository followed by a checkout in there. But the clone does a lot of work and pulls down all the revision state. Is there any lightweight way of saying "grab me the current state of the world at this commit/tag and spray it into this directory?" (Further revision control not necessary-- it's "read only" as far as Git should be concerned.)

Maybe not-- just checking.

Thanks.

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

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

发布评论

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

评论(3

心头的小情儿 2024-10-05 16:35:05

如果都是本地的,你可以这样做:

mkdir /path/to/test-tree
cd /path/to/repo
git read-tree <tag>
git checkout-index -a --prefix=/path/to/test-tree/  # don't forget the last slash

# read-tree copies content into the index
# to restore it:
git read-tree HEAD

假设你根本不关心另一棵树有任何 git 信息。如果您愿意,可以使用 git-new-workdir 脚本,它基本上创建一个克隆,除了用返回原始的符号链接填充 .git 目录repo,这样就不需要额外的磁盘空间。这是一种很好的方法 - 不需要额外的磁盘空间,并且您可以使用一个存储库进行开发,一个用于测试等。

If it's all local, you can do this:

mkdir /path/to/test-tree
cd /path/to/repo
git read-tree <tag>
git checkout-index -a --prefix=/path/to/test-tree/  # don't forget the last slash

# read-tree copies content into the index
# to restore it:
git read-tree HEAD

That's assuming you don't care about the other tree having any git information at all. If you want it to, you could use the git-new-workdir script, which basically creates a clone, except populating the .git directory with symlinks back to the original repo, so that it takes no extra disk space. It's a nice approach - no extra disk space, and you can use one repo for development, one for testing, etc.

最美不过初阳 2024-10-05 16:35:05

尝试

git checkout -b new_branch [previous_tag]

Try

git checkout -b new_branch [previous_tag]
唯憾梦倾城 2024-10-05 16:35:05

听起来你正在寻找 git-export:做一个“ git 导出”(如“svn 导出”)?

Sounds like you're looking for git-export: Do a "git export" (like "svn export")?

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