我有一些提交由git subtree我想要垃圾收集(更多的任何实际目的只是为了了解什么和为什么可以收集).
我已经检查过这些提交没有通过以下方式引用:
# In any reflog
> git reflog --all --no-abbrev-commit | grep <hash>
(no output)
# In any branch, local or remote
> git branch --contains <hash>
(no output)
> git branch -r --contains <hash>
(no output)
# In any tag
> git tag --contains <hash>
(no output)
# In the current index
> git rev-list HEAD | grep <hash>
(no output)
# In references from filter-branch
> ls .git/refs/original/
(the folder does not exist)
Run Code Online (Sandbox Code Playgroud)
这些是 …
首先 - 向这个问题道歉.关于它的话题已经很多了.但我对他们没有太多运气.我对git缺乏熟悉并没有多大帮助.
我正在将一个文件夹从一个git repo移动到另一个(已经存在).例如
repo-1
---- dir1
---- dir2
---- dir3
---- dir-to-move
---- dir5
repo-2
---- dir1
---- dir2
---- dir3
Run Code Online (Sandbox Code Playgroud)
最后我希望回购看起来像
repo-1
---- dir1
---- dir2
---- dir3
---- dir-to-move
---- dir5
repo-2
---- dir1
---- dir2
---- dir3
---- dir-to-move
Run Code Online (Sandbox Code Playgroud)
也就是说,在两个回购中都存在dir-to-move.但最终我会将最新的更改迁移到repo-2并从repo-1中移除dir-to-move.
我最初的研究让我相信我需要使用filter-branch.例如
如何使用`git format-patch`和`git am`将文件从一个git repo移动到另一个保存历史记录
我已经知道子树取代了这种方法.然而,它并没有达到我的预期.我以为我能够做类似的事情
在repo-1工作区中
git subtree split -P dir-to-move -b split
Run Code Online (Sandbox Code Playgroud)
将拆分分支过滤到仅dir-to-move及其历史记录.然后在repo-2工作区 …
我想将我的git存储库中的文件夹拆分为新文件夹.但我想保留所有与此文件夹相关的所有打开/关闭分支和历史记录.
\ Source Repo
--\ AAA
--\ BBB
----\ DDD
----\ EEE
--\ CCC
\ New Repo 1
--\ AAA
--\ CCC
\ New Repo 2 (BBB subfolder)
--\ DDD
--\ EEE
Run Code Online (Sandbox Code Playgroud)
我按照此处描述的步骤https://help.github.com/articles/splitting-a-subfolder-out-into-a-new-repository/ - 但这仅适用于单个分支.最后 - 我获得了所有(?)提交的新存储库,但没有分支信息.
我尝试使用--all参数为所有分支执行此操作,但我不清楚如何将所有重写的分支推送到空的远程仓库.
这是我目前的情况:
$ git clone https://github.com/USERNAME/REPOSITORY-NAME
$ cd REPOSITORY-NAME
$ git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME -- --all
Run Code Online (Sandbox Code Playgroud)
在这一点上,如果我看看我的本地回购,我似乎有所有历史和所有分支在遥控器的起源.
$ git remote -v
origin https://github.com/USERNAME/REPOSITORY-NAME.git (fetch)
origin https://github.com/USERNAME/REPOSITORY-NAME.git (push)
$ git remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git
$ git remote -v
origin https://github.com/USERNAME/NEW-REPOSITORY-NAME.git …Run Code Online (Sandbox Code Playgroud)