【问题标题】:Overwriting files on local disk from github (using Laravel framework)从 github 覆盖本地磁盘上的文件(使用 Laravel 框架)
【发布时间】:2016-05-17 07:57:24
【问题描述】:

我正在尝试执行以下操作:

1) 使用以下命令创建一个新的 laravel 项目:

sudo composer create-project laravel/laravel /var/www/html/laravel5`

2) 仅覆盖来自 github 的不同文件。我想保持以下文件和文件夹不变:

  • .env
  • .env.example
  • .gitattributes
  • .gitignore
  • vendor/

由于文件夹不为空,无法从 github 克隆。

我发现的唯一解决方法是:

  1. 创建一个新项目
  2. 将我想要的文件和文件夹复制到另一个文件夹
  3. 从 github 克隆项目
  4. 将文件复制回文件夹

我正在使用 Xubuntu、Laravel 5.0 和 Github。

提前致谢。

【问题讨论】:

  • “仅覆盖来自 github 的不同文件”是什么意思?你从哪个 git repo 克隆?
  • 我的存储库。我想保留使用“laravel new”命令创建的文件。

标签: php git laravel github laravel-5


【解决方案1】:

您应该能够通过全 git 方法而不是从另一个目录复制/粘贴来执行此操作。 (不过,我不确定为什么您的解决方法是一个糟糕的解决方案。)

基本计划是:

  1. 创建存储库。
  2. 检查一些您不会保留的虚假分支。
  3. 将要保留的目录添加到索引并提交。
  4. 强制结帐到您想要的分支。由于您没有刚刚提交的其他事情,它可能需要强制执行。
  5. 将最近创建的提交的补丁应用到您的工作目录。

在命令中:

cd /path/to/repo
git init
git branch temp-branch
git add .env && git add .env.example && git add .gitattributes && git add .gitignore && git add vendor/
git commit -m "Sustain Local Changes"
git remote add origin https://github.com/owner/repo
git fetch
git checkout -f master # Should detect origin/master. If it doesn't, just set a branch up manually. Replace master if that's not the branch you want.
git merge --no-commit --no-ff temp-branch

就我个人而言,我觉得这比你的解决方法丑得多。

【讨论】:

  • 我意识到您可能在合并时遇到了冲突。如果是这样,只需使用 -X 命令之一。可能是theirs
猜你喜欢
  • 2023-03-13
  • 2013-03-24
  • 2018-04-04
  • 2020-07-20
  • 2014-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多