【问题标题】:Git: How to push dist directory to a separate branch of the same repositoryGit:如何将 dist 目录推送到同一存储库的单独分支
【发布时间】:2023-03-09 18:19:02
【问题描述】:

我在现有存储库中有一个项目,文件夹结构:

myproject (master)
+-- app/ (master)
+-- dist/ (in .gitignore, but i need it as other branch)
+-- node_modules (.gitignore)
+-- index.html (master)
+-- gulpfile.babel.js (master)
+-- package.json (master)

有没有办法将dist 推送到同一存储库的单独分支?
澄清一下,我只想要deploy 分支中的dist 文件,并将其他文件保留在master 中。

【问题讨论】:

    标签: git deployment gulp gitlab git-branch


    【解决方案1】:

    有没有办法将dist 推送到同一存储库的单独分支?

    有,使用git submodule

    • 创建一个orphan branch'deploy'
    • dist 文件夹内容复制到空仓库中,添加并提交,然后推送。
    • 将该分支添加为dist 文件夹子模块。

    即:

    git checkout --orphan deploy
    # copy your folder content
    git add .
    git commit -m "deploybranch folder content"
    git push -u origin deploy
    

    然后

    git checkout master
    git submodule add -b deploy -- /remote/url/of/your/own/repo dist
    git commit -m "Add deploy branch as submodule"
    git push
    

    在您的master 分支中,您将通过dist 根文件夹子模块保留对deploy 的引用。

    话虽如此,请记住生成和部署的内容通常存储在控制文件系统中,而是存储在像Nexus这样的二进制引用中或Artifactory: 确保不要在其中保存巨大的二进制文件。

    【讨论】:

    • 感谢您回答我的问题,当我将部署分支添加为子模块时,它说 The following path is ignored by one of your .gitignore files: dist Use -f if you really want to add it. 我应该从 .gitignore 中删除 /dist 文件夹吗?不是/dist 会推送到master branch 吗?您对此有解决方案吗?
    • @vanio178 只需从您的 .gitignore 文件中删除 dist:您不再需要忽略该文件夹。
    • 很抱歉再次请求您的帮助,但现在它说:repo URL: 'deploy' must be absolute or begin with ./|../@VonC​​pan>
    • @vanio178 在哪个命令上? git子模块添加?您必须使用远程远程地址。
    • 是的@VonC,它在命令git submodule add。我认为我的远程 url 格式不正确? git submodule add -b -f deploy -- https://gitlab.com/<company>/<project>/myproject-web.git/dist(branch name)/dist
    猜你喜欢
    • 2015-03-01
    • 2013-05-09
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2010-09-26
    • 1970-01-01
    相关资源
    最近更新 更多