gpt4 book ai didi

git - 如何更改 git 历史记录中的文件路径?

转载 作者:太空狗 更新时间:2023-10-29 13:30:21 25 4
gpt4 key购买 nike

这是我所拥有的 - 我的代码的 git 存储库:

projects
|-proj1 (no git repo here yet)
|-subproj1 <- current git repo here

这就是我想要的 - 一个 git 存储库,它现在正在跟踪一个使用我的代码的新项目:

projects
|-proj1 <-git repo moved to here, but still tracking files in subproj1
|-subproj1 (no git repo here)

我想保持历史完整,因此新存储库将引用比原始文件更深一层的文件。最无痛的方法是什么?

最佳答案

可以使用 git filter-branch 命令重写历史。事实上,将目录树移动到子目录是 git filter-branch 中给出的剪切和粘贴就绪示例之一。手册页:

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

关于git - 如何更改 git 历史记录中的文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3058560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com