从远程仓库有效复制 git 工作树
我的服务器上有一个远程裸存储库。我希望服务器始终将当前工作树作为系统中的真实目录。
我正在使用 post-receive git-hook 和命令来构建工作树并覆盖旧树:
git archive master | tar -x -C /dir/to/my/project/
但是,这种方法有一个问题:它不会删除存储库中已删除/移动的文件。
我可以简单地删除整个项目目录,但我想保留 .gitignore 中忽略的所有文件。
我尝试编写一个脚本来删除所有未被忽略的文件,但需要几分钟的时间来处理。
有没有办法复制工作树而不删除被忽略的文件?
I have a remote bare repo on my server. I want the server to always have the current working tree as a real directory in the system.
I am using the post-receive
git-hook with a command to build the working tree and to override the old tree:
git archive master | tar -x -C /dir/to/my/project/
However, this approach has a problem: It does not delete files that were deleted/moved in the repo.
I could simply erase the whole project directory but I want to keep all files that are ignored in my .gitignore.
I tried to write a script to delete all files that are not ignored but it takes minutes to process.
Is there a way to replicate the working tree without erasing ignored files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用便利命令添加工作树(实际上不是最好的计划,但可能可行),也可以使用核心命令自己实现您需要的部分(保证始终工作相同)。
索引是一个清单、路径名列表和指向存储库内容的指针以及该路径上文件系统副本的缓存文件系统元数据。
你把工作树和索引放在哪里完全取决于你,Git 的核心并不关心,只要告诉它(就像我在这里所做的那样)。
$commit:$dir
修订版的文档语法git read-tree
是结帐、合并、硬重置和任何类似操作的核心命令。You can either add worktrees with the convenience command (not really the best plan, but probably workable) or implement the parts you need yourself with core commands (guaranteed to always work the same).
The index is a manifest, a list of pathnames and pointers to repo content and cached filesystem metadata for the filesystem copy at that path.
Where you put the work tree and index is entirely up to you, Git's core doesn't care, just tell it (as I've done here).
Docs for the
$commit:$dir
revision syntaxgit read-tree
is the core command underlying checkout, merge, hard resets, and anything of the kind.