如何更改git历史中的文件路径? [英] How do I change a file's path in git's history?
问题描述
以下是我的代码 - 我的代码的git回购:
项目
| -proj1(no git repo here)
| -subproj1< - 当前git repo here
这里是我想要的是一个git仓库,它正在跟踪使用我的代码的新项目:
项目
| - proj1< -git repo移动到这里,但仍然在跟踪subproj1中的文件
| -subproj1(这里没有git repo)
我想保持历史记录不变,因此新存储库将引用比原始文件更深一级的文件。什么是最痛苦的方式来做到这一点?
使用 Here is what I have - a git repo of my code: Here is what I want - a git repo which is now tracking a new project that uses my code: I'd like to keep the history intact and therefore the new repository will be referring to files that are one level deeper than the original. What is the most pain free way to do this? Rewriting history can be done with the
这篇关于如何更改git历史中的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! git filter-branch
命令可以完成重写历史记录。实际上,将一个目录树移动到一个子目录中是 >
git filter-branch --index-filter'
git ls-files -s |
seds-\ t \* - & subproj1 / - |
GIT_INDEX_FILE = $ GIT_INDEX_FILE.new git update-index --index-info&&
mv $ GIT_INDEX_FILE.new $ GIT_INDEX_FILE
'HEAD
projects
|-proj1 (no git repo here yet)
|-subproj1 <- current git repo here
projects
|-proj1 <-git repo moved to here, but still tracking files in subproj1
|-subproj1 (no git repo here)
git filter-branch
command. In fact, moving a directory tree into a subdirectory is one of the cut&paste-ready examples given in the git filter-branch
manpage:git filter-branch --index-filter '
git ls-files -s |
sed "s-\t\"*-&subproj1/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
' HEAD