linux - Git 推送到 master repo 然后将 dist 文件夹发送到特定路径(/www/site/v0.0.1)?

标签 linux git bash

因此,我的目标是将我的项目推送到一个核心存储库,我所有的开发文件都存储在该存储库中,以供备份。

然后我想发送 dist文件夹到类似 www/site.com/v0.0.1 的目录,出于演示目的,不需要开发文件,它只会导致膨胀,因为我有多个目录。


所以我现在拥有的是 .gitignore这几乎忽略了除 dist 之外的所有内容.

我跑了 git rm -r --cache现在我只推 dist , 但现在的问题是我无法备份我的核心仓库,万一我的本地环境被破坏,那么我所拥有的就是所有这些编译后的代码,我不是逆向工程。

#!/bin/sh
currentVersion=git describe --abbrev=0
mkdir /var/www/example.com/public_html/projects/$currentVersion
git --work-tree=/var/www/example.com/public_html/projects/$currentVersion --git-dir=/var/repo/cool.git checkout -f

我可以想到两种情况

  1. 两个远程仓库(core.git、demos.git),git add remote <ssh-repo/core.git & demos.git> , 陷阱在于 .gitignore我应该如何指定哪个 repo 使用忽略?两个 repo 协议(protocol)也很糟糕。

  2. 在 bash 脚本中写一些东西,使我能够忽略文件,然后添加另一个工作树,或者可能只使用 linux 命令获取 dist 并将其放入我想要的版本中 post-receive事件?

三分之一可能会使用分支,我仍然是一个 git 新手,不确定我能做什么。

编辑: 如果我只是推送 dist 文件夹,显然两个 repo 是愚蠢的,所以我认为在 bash 脚本中我需要以某种方式只获取 dist 文件夹并使用命令来复制它进入我想要的路径。

最佳答案

如果 dist 目录只包含生成的工件,并且可以从其余的 core 文件中重新创建,我建议使用 2 个 repos:

  • dist 用于生成的工件
  • 其余的
  • core 加上指向 dist 存储库的符号链接(symbolic link)(是否添加到 git,每个都有优点和缺点,由您决定)

沿着这条线的东西(他们不必并排,只要你方便):

$~/git> ls -la *
core:
total 36
drwxrwxr-x 3 user at  4096 Apr 22 22:22 .
drwxrwxr-x 4 user at  4096 Apr 22 22:22 ..
-rw-rw-r-- 1 user at 22811 Apr 22 22:22 blah
lrwxrwxrwx 1 user at     7 Apr 22 22:22 dist -> ../dist
drwxrwxr-x 8 user at  4096 Apr 22 22:23 .git

dist:
total 16
drwxrwxr-x 3 user at 4096 Apr 22 22:23 .
drwxrwxr-x 4 user at 4096 Apr 22 22:22 ..
-rw-rw-r-- 1 user at   84 Apr 22 22:24 blah_dist
drwxrwxr-x 8 user at 4096 Apr 22 22:24 .git

不需要 .gitignore 文件。 从 core 目录推送到源代码备份仓库,从 dist 目录推送(甚至从 core 内的符号链接(symbolic link)下)推送到部署 repo 协议(protocol)。 Git 足够聪明,不会混淆这两个存储库:

$~/git/core> git status
On branch master
nothing to commit, working directory clean
$~/git/core> cd dist/
$~/git/core/dist> git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   blah_dist

no changes added to commit (use "git add" and/or "git commit -a")
$~/git/core/dist> 

即使您有一些文件应该由两个存储库共享,您也可以将它们视为“生成的”:将它们放在 core 存储库中并通过简单复制到 中“生成”它们根据需要分配符号链接(symbolic link)/ repo 。

您甚至可以使用 git push hook 自动生成/刷新 dist 工件在核心 存储库中。

关于linux - Git 推送到 master repo 然后将 dist 文件夹发送到特定路径(/www/site/v0.0.1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806566/

相关文章:

linux - 根据 AWS "--profile"更改用户的命令提示符颜色

linux - 我在哪里可以找到 vim 增强的资源?

c - Linux下socket如何生成随机文件名?

git - 如何构建一个 git 轮询构建机器人?

git - .git 目录是否包含远程密码或 SSH key ?

git - Git 中的什么等同于 ClearCase 中的只读组件?

java - 根据Java版本运行不同的Bash命令

c - popen() 和 sleep() 调用不起作用

linux - 带有 DB 的主机端口到 Docker 容器

bash - 使用 fd 嵌套 while 读取循环