错误将git存储库合并到子目录中 [英] error combining git repositories into subdirs

查看:125
本文介绍了错误将git存储库合并到子目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看过几个解决这个问题的线索。

结合多个git存储库



结合多个名称中有空格的git仓库



我还查看了git filter-branch联机帮助页。






更新



我已更改为2个脚本系统:

 #!/ bin / bash 
git filter-branch --index-filter'〜/ doit.sh'HEAD


< >#!/ bin / bash
git ls-files -s | \
seds-\t-& data / perl_modules / - | \
GIT_INDEX_FILE =$ GIT_INDEX_FILE.newgit update-index --index-info&& \
mv$ GIT_INDEX_FILE.new$ GIT_INDEX_FILE

这避免了以前错误,但现在得到这个(替换路径为[...]):

 重写c35e4ef0626fb2045f57fa5b605e7663b8d06196(1/10977)mv:不能stat [[...] /。git-rewrite / t /../ index.new':没有这样的文件或目录
索引过滤失败:〜/ doit.sh

当我运行

  ls -files-s | sed ... | git update-index ... 

我得到它应该生成的索引文件。以及当我更改doit.sh文件输出sed的结果,而不是管道它的git update-index它似乎产生适当的输出...它似乎git update-index是根本不创建文件时运行--index-filter ....






再次更新:

当我更改



$ GIT_INDEX_FILE.new$ GIT_INDEX_FILE



p>

$ GIT_INDEX_FILE.new$ GIT_INDEX_FILE|| true



第一个mv失败,但其他所有(迄今为止)都在工作。
$ b

所有这些在脚本中达到高潮:

  git filter-branch --index-filter \ 
'git ls-files -s | seds-\\\\* - & data / perl_modules / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new \
git update-index --index-info&&
mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE'HEAD

理论上这个脚本应该将所有文件在存储库中,将它们推入到data / perl_modules /中,并重写历史记录,以便它看起来文件一直位于该目录中。



然而,我得到这个错误:

 致命:ambiguous argument'ls-files':未知版本或路径不在工作树中
使用' - - '将路径与修订版分开

不知道如何继续,我无法很好地理解脚本足以调试它,它直接从git filter-branch联机帮助文件中获取。



我已经在手动将文件移动到subdir之前和之后尝试过这种情况它需要它们被移动,或者需要它们不会被移动。

解决方案



1)git filter-branch --index过滤器没有正确使用'...'。

我不确定这是为什么,git-filter的一个bug,一个环境问题?谁知道。但是我能够通过将所有内容都移出'...'并将其放入脚本文件来修复它。然后我调用脚本里的''

  git filter-branch --index-filter'〜/ doit.sh'HEAD 

和doit.sh:

 #!/ bin / bash 

git ls-files -s | \
seds-\t-& data / perl_modules / - | \
GIT_INDEX_FILE =$ GIT_INDEX_FILE.newgit update-index --index-info

mv$ GIT_INDEX_FILE.new$ GIT_INDEX_FILE|| true

2)第一次提交是空的,所以没有index.new到mv



这个git repo是使用git-svn从svn导入的。因此,第一次提交完全是空的,只是说初始svn回购初始化。因此没有文件移动,也没有index.new移动。这通过添加||来解决真正的mv命令。但是请注意,如果多个mv命令失败,您还有其他问题。


I have looked at several threads addressing this.

Combining multiple git repositories

Combining multiple git repositories having a space in their name

I also looked at the git filter-branch manpage.


update

I have changed to a 2 script system:

#!/bin/bash
git filter-branch --index-filter '~/doit.sh' HEAD

and doit.sh

#!/bin/bash
git ls-files -s | \ 
    sed "s-\t-&data/perl_modules/-" | \ 
    GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info && \
    mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"

This avoids the previous error, but now gets this (replaced path with [...]):

Rewrite c35e4ef0626fb2045f57fa5b605e7663b8d06196 (1/10977)mv: cannot stat `[...]/.git-rewrite/t/../index.new': No such file or directory
index filter failed: ~/doit.sh

When I run the

ls-files- s | sed ... | git update-index ...

I get the index file it should generate. As well when I change the doit.sh file to output the result of sed instead of piping it to git update-index it appears to produce the proper output... it seems git update-index is simply not creating the file when run under --index-filter....


Update again:

When I change

mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"

to

mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true

It fails the first mv, but all the others (so far) are working.


All of this culminated in this script:

git filter-branch --index-filter \
    'git ls-files -s | sed "s-\t\"*-&data/perl_modules/-" |
            GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                    git update-index --index-info &&
     mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD

Theoretically this script should take all the files in the repository, shove them into data/perl_modules/, and rewrite history so that it appears the files have always been in that directory.

However I get this error:

fatal: ambiguous argument 'ls-files': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

Not sure how to proceed, I don't understand the script well enough to debug it, and it is taken directly from the git filter-branch manpage.

I have tried this both before and after manually moving the files to the subdir in case it required they be moved, or required they not be moved.

解决方案

There were a couple problems.

1) git filter-branch --index filter was not using the '...' properly.

I am not sure why this is, a bug with git-filter, an environment problem? who knows. But I was able to fix it by moving everything out of the '...' and putting it into a script file. I then called the script inside the ''

git filter-branch --index-filter '~/doit.sh' HEAD

And doit.sh:

#!/bin/bash

git ls-files -s | \ 
    sed "s-\t-&data/perl_modules/-" | \ 
    GIT_INDEX_FILE="$GIT_INDEX_FILE.new" git update-index --index-info

mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true

2) The first commit was empty, so there was no index.new to mv

This git repo was imported from svn using git-svn. As such the first commit was completely empty simply saying initial svn repo initialization. As such there were no files moved, and no index.new to move. This was solved by adding || true to the mv command. Note however that if more than one mv command fails you have other problems.

这篇关于错误将git存储库合并到子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆