git - 我们可以在分支上创建一个空提交而不切换到它吗
问题描述
简而言之,存储库又旧又大,比如说 7GB。例如,当前分支是branch01
,远程被调用origin
。任务是在branch02
. 基本上,空提交是在执行 git-push 时触发 CI(持续集成)过程。
然而,从一个分支切换到另一个分支可能需要几秒钟,甚至几分钟,因为可能会有大量的 IO 操作。有没有办法在不切换到它的情况下创建空提交branch02
,就像下面一样。
# to create the empty commit
# git command: hash-object, write-tree, commit-tree
# after the empty commit is created
git push origin branch02:branch02
解决方案
只是为了回答最初的问题,您可以使用一些低级命令来做到这一点:
cmt=$(git commit-tree -m "trigger Jenkins" -p branch02 branch02^{tree}) &&
git update-ref refs/heads/branch02 $cmt
也就是说,您创建一个新的提交对象,其树对象与原始分支相同,原始分支作为父分支,然后将分支指向新提交。
推荐阅读
- python - 使用 Python 将文件导入和保存到 NOSQL 数据库
- vba - 我是否需要 Microsoft 开发人员版工具许可证才能在 Office 2000 到 Office 2007 中的 VBA 中编码?
- swift - 子类化问题:来自子类的字典值?
- reactjs - 如何通过 Route 和容器组件传递道具?
- c# - 关于从另一个程序集中提取引用
- java - Java——在不返回新变量的情况下更改参数
- python - 将文本段落拆分为句子时迭代行
- unit-testing - 如何测试/重构以测试调用 http.ListenAndServe 的函数
- android - 如何使用 Rx2AndroidNetworking 从 json API 缓存内容和数据?
- python - Web-Scraping Python,DataFrame 的索引问题