我有,我最初使用的子模块进行一些相关的代码项目。 事实证明,子模块是不是真的适合这个项目(和他们很难在实际中使用),所以我每个子模块转换成子树(使用新的git-subtree
功能)。
在我工作的仓库,我已经成功地删除每个子模块,并添加了旧子模块回购作为一个子。 没有问题与此有关。
当我去到另一个克隆并尝试从第一个拉,我从合并的步骤以下错误:
error: The following untracked working tree files would be overwritten by merge:
sub/.gitignore
sub/Makefile
sub/README
sub/src/main.c
... and so on for all files in sub/
Aborting
看来,这是因为在文件sub/
从来没有真正在主存储库摆在首位存在,当Git的应用补丁更新.gitmodules
它不与子模块文件,删除目录。 当处理下一个承诺,在Git的尝试创建新的文件sub/
那是现在的主要仓库的部分,全部用在仍然存在的文件这些文件冲突sub/
。
我已经找到了解决办法是使用rm -rf sub
之前git pull
,这避免了这个问题。
我的问题是,是否有任何命令行开关我可以用git merge
,说“覆盖这种情况发生在工作目录中存在的任何文件”? 更妙的是一个功能, git merge
会看现有文件的内容,如果内容是相同的它要创建反正文件,取消错误信息,然后继续。
更新 :我已经创建了一个演示此问题,展现的正是我想说的Git仓库。 要重现:
$ git clone https://github.com/ghewgill/q14224966.git
$ cd q14224966
$ git submodule init
$ git submodule update
$ git merge origin/branch
这将导致错误消息
error: The following untracked working tree files would be overwritten by merge:
sub/Makefile
sub/README
sub/src/main.c
Please move or remove them before you can merge.
Aborting
我知道你的问题是具体的合并,但我已经与合并git的子模块类似的问题。 我认为,这个解决方案将与你的问题的工作,即使它不能直接解决问题的合并。
我发现,通过强制检查出你要合并的分支,然后回到主,一切顺利与子模块。
要得到的东西在你的榜样工作:
$ git clone https://github.com/ghewgill/q14224966.git
$ cd q14224966
$ git submodule init
$ git submodule update
$ git checkout -f origin/branch
$ git checkout master
$ git merge origin/branch
这工作,因为它基本上做你的rm -rf
为您一步。 当然,这是一个有点迂回,也许不值得做的,如果你只有一个子模块喜欢你的例子一样。 但我发现它与许多子模块项目工作时,是相当的节省时间。
此外,正如在评论中所指出的,如果你想避免在更改工作树,你可以这样做:
$ git clone https://github.com/ghewgill/q14224966.git
$ cd q14224966
$ git submodule init
$ git submodule update
$ git reset origin/branch
$ git reset --hard master
这部作品在大致相同的方式,但避免了在这个过程中检查出其他文件。 我还没有机会在野外使用,但它似乎是一个完善的方法。
还有$ git merge -s subtree origin/branch
。 它与你的榜样,但是,当一个以上的子模块参与我有意想不到的效果吧。 你可能有更好的运气,虽然。
你不能得到git-merge
(或任何其它命令)强行破坏它不认为它知道,没有文件。 混帐试图相当困难,不要做任何完全不可逆的。
但有许多子模块,你可以让你的缺失更容易一点,更安全的使用git submodule foreach
:
$ git submodule foreach 'rm -rf $toplevel/$path'
Entering 'sub'
$ git merge origin/branch
Updating a231acd..6b4d2f4
Fast-forward
...
(警告:我从来没有与子树工作,我不知道你的实际回购的复杂程度,所以这些解决方案实际上可能并不适合你。)
从玩弄你的样品回购,我发现了两个解决方案都似乎工作,虽然他们产生不同的承诺树:
使用git merge -s resolve origin/branch
~/q14224966[master]> git reset --hard origin/master HEAD is now at a231acd add submodule ~/q14224966[master]> touch other.c && git add . && git commit -m "New commit." [master bc771ac] New commit. 0 files changed create mode 100644 other.c ~/q14224966[master]> git merge -s resolve origin/branch Trying really trivial in-index merge... error: Merge requires file-level merging Nope. Trying simple merge. Simple merge failed, trying Automatic merge. Adding sub/Makefile Adding sub/README Adding sub/src/main.c Merge made by the 'resolve' strategy. .gitmodules | 3 --- sub | 1 - sub/Makefile | 1 + sub/README | 1 + sub/src/main.c | 1 + 5 files changed, 3 insertions(+), 4 deletions(-) delete mode 160000 sub create mode 100644 sub/Makefile create mode 100644 sub/README create mode 100644 sub/src/main.c ~/q14224966[master]> ls README main.c other.c sub/ ~/q14224966[master]> cd sub/ ~/q14224966/sub[master]> ls Makefile README src/ ~/q14224966/sub[master]> git status # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # nothing to commit (working directory clean) ~/q14224966/sub[master]> cd .. ~/q14224966[master]> git status # On branch master # Your branch is ahead of 'origin/master' by 5 commits. # nothing to commit (working directory clean)
这里的commit的结果树:
使用衍合,而不是合并:
~/q14224966[master]> git reset --hard origin/master HEAD is now at a231acd add submodule ~/q14224966[master]> touch other.c && git add . && git commit -m "New commit." [master ae66060] New commit. 0 files changed create mode 100644 other.c ~/q14224966[master]> git rebase origin/branch First, rewinding head to replay your work on top of it... Applying: New commit. ~/q14224966[master]> ls README main.c other.c sub/ ~/q14224966[master]> cd sub/ ~/q14224966/sub[master]> ls Makefile README src/ ~/q14224966/sub[master]> git status # On branch master # Your branch is ahead of 'origin/master' by 4 commits. # nothing to commit (working directory clean) ~/q14224966/sub[master]> cd .. ~/q14224966[master]> git status # On branch master # Your branch is ahead of 'origin/master' by 4 commits. # nothing to commit (working directory clean)
这里的commit的结果树:
它试图
混帐取--all
GIT中的复位 - 硬起源/主
但它不工作。
您可以使用“我们的”合并策略:
混帐合并-s我们的老主
你也可以使用git-藏匿保存更改然后混帐藏匿申请恢复。