如何使用index-filter& amp; amp; amp; amp; id =合作 [英] How to extract one file with commit history from a git repo with index-filter & co

查看:111
本文介绍了如何使用index-filter& amp; amp; amp; amp; id =合作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是,我有一个从SVN转换为HG的git repo,我想只提取一个源文件。我也有奇怪的字符,如a(编码不匹配损坏的Unicodeä)和文件名中的空格。



看起来不是那么容易,这就是我将会回答我自己的问题,尽管有许多关于git [index-filter | subdirectory-filter | filter-tree]的类似问题,因为我需要使用以前的所有功能来实现这一点!



所以问题是:我如何从一个存储库中提取一个文件并将它放在新的repo的根目录? 解决方案

首先要注意的是,即使是在评论将git仓库中的一组文件分割到他们自己的仓库中,保留相关的历史记录

  SPELL ='git ls-tree -r --name-only --full-tree$ GIT_COMMIT| grep -vtrie.lisp| tr\\\
\0| xargs -0 git rm --cached -r --ignore-unmatch'
git filter-branch --prune-empty --index-filter$ SPELL - --all

对名为像 imaging / DrinkkejaI< 0300> $'\302 \ 210' .txt_74x2032.gif
aI< 0300> $'\302\210'部分曾经是单个字母:ä



  git filter-branch -f --subdirectory-filter lisp / source / model HEAD 

或者,您可以使用--tree-filter:
(需要进行测试,因为该文件早前位于另一个目录中,请参阅:
如何在Git仓库中移动目录所有提交?

  MV_FILTER ='test -f source / model / trie.lisp&& mv ./source/model/trie.lisp。 || echoNothing to do。'
git filter-branch --tree-filter $ MV_FILTER HEAD --all

要查看文件的所有名称,请使用:

  git log --pretty = oneline  - -follow  - 仅限名称git-path / to / file | grep -v''| sort -u 

http://whileimautomaton.net/2010/04/03012432



另外请按照以下步骤操作:

  $ git reset --hard 
$ git gc --ggressive
$ git prune
$ git remote rm origin#否则变更将被推到克隆仓库的位置


My situation was, I have a git repo converted from SVN to HG to GIT, and I wanted to extract just one source file. I also had weird characters like aÌ (an encoding mismatch corrupted Unicode ä) and spaces in the filenames.

Seems it's not particularly easy, and that's the reason I'll be answering my own question despite many similar questions regarding git [index-filter|subdirectory-filter|filter-tree], as I needed to use all the previous to achieve this!

So the question is: "How can I extract one file from a repository and place it at the root of the new repo?"

解决方案

First a quick note, that even a spell like in a comment on Splitting a set of files within a git repo into their own repository, preserving relevant history

SPELL='git ls-tree -r --name-only --full-tree "$GIT_COMMIT" | grep -v "trie.lisp" | tr "\n" "\0" | xargs -0 git rm --cached -r --ignore-unmatch'
git filter-branch --prune-empty --index-filter "$SPELL" -- --all

will not help with files named like imaging/DrinkkejaI<0300>$'\302\210'.txt_74x2032.gif. The aI<0300>$'\302\210' part once was a single letter: ä.

So in order to extract a single file, in addition to filter-branch I also needed to do:

git filter-branch -f --subdirectory-filter lisp/source/model HEAD

Alternatively, you can use --tree-filter: (the test is needed, because the file was at another directory earlier, see: How can I move a directory in a Git repo for all commits?)

MV_FILTER='test -f source/model/trie.lisp && mv ./source/model/trie.lisp . || echo "Nothing to do."'
git filter-branch --tree-filter $MV_FILTER HEAD --all

To see all the names a file have had, use:

git log --pretty=oneline --follow --name-only git-path/to/file | grep -v ' ' | sort -u

As described at http://whileimautomaton.net/2010/04/03012432

Also follow the steps on afterwards:

$ git reset --hard
$ git gc --aggressive
$ git prune
$ git remote rm origin # Otherwise changes will be pushed to where the repo was cloned from

这篇关于如何使用index-filter&amp; amp; amp; amp; amp; id =合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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