【问题标题】:Git Rebase: Adding files after directory structure changedGit Rebase:更改目录结构后添加文件
【发布时间】:2020-03-25 14:55:56
【问题描述】:

我有以下场景:

我有 Repo1,我在 Repo2 中创建了一个副本,方法是克隆 Repo1,然后将源更改为 Repo2。到目前为止,一切都很好。 No in Repo 2 我想创建一个 src 文件夹并将所有文件移动到其中,这样我们就有以下情况:

回购1:

- file1
- folder1
  -file2

回购2:

-src
  - file1
  - folder1
    -file2

到目前为止一切顺利。不,当我将 Repo2 重新定位到 Repo1,并且 file1 已更改时,它会检测到这一点并将更改添加到 Repo2 的 src 文件夹内的正确 file1 中。

问题是当我在 Repo1 中添加一个文件然后 rebase 它没有检测到这一点并将新文件放在 src 文件夹之外。

关于如何解决此问题以实现平滑变基的任何提示?

非常感谢!

【问题讨论】:

  • Git 不管理目录,只管理单个文件。您需要围绕它编写脚本。

标签: git directory structure rebase


【解决方案1】:

假设 Repo2 中不在 Repo1 中的第一个提交正在将文件移动到子目录中:

git switch -c tmp repo-1/master
git rm -r *
mkdir src
git read-tree --prefix=src -u HEAD
move_commit=$(git rev-list repo-1/master..master | tail -1)
git commit --no-edit -c $move_commit
git rebase --onto tmp $move_commit master
git branch -d tmp

或者,如果您不坚持变基,您可以执行以下任一操作:

  • git merge -s subtree repo-1/master
  • git subtree pull --prefix=src repo-1 master

【讨论】:

    猜你喜欢
    • 2021-10-16
    • 2015-01-11
    • 1970-01-01
    • 2016-05-26
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 2013-06-12
    • 2012-03-06
    相关资源
    最近更新 更多