添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Let’s say you have two projects that were living in their own repository for ages. And all of a sudden it make sense to move a subset of code, and its whole commit history, from the first to the second. That’s a topic I already addressed. See for instance my previous articles on an internal corporate project I open-sourced migration from SVN to , and Git sub-tree cleaning Should we really keep revisiting the subject again and again? Yes, cause things have changed! Since v1.7.2 , Git supports orphan branches. And we’ll now use them to keep unrelated branches sharing the same root until their merging point. We start with the source repository. The code we’re about to move is available in the develop branch:
$ git clone https://github.com/kdeldycke/source-project.git
$ cd ./source-project
$ git checkout develop
 I revisited the new commit log which was way cleaner. But the command above was
too much coarse-grained, so I had to repeat the operation again to get the
exact sub-tree I was looking for:
$ git filter-branch --force --prune-empty --tree-filter 'find . -type f -iname ".gitignore" -print -exec rm -rf "{}" \;' -- --all
$ git filter-branch --force --prune-empty --tree-filter 'if [ -d ./calibration ]; then rm -rf ./calibration; fi' -- --all
$ git filter-branch --force --prune-empty --tree-filter 'if [ -f ./script_tools.py ]; then mkdir -p ./folder3/scripts; mv ./script_tools.py ./folder3/scripts/; fi' -- --all
(...)
Could not apply 2a4f66a6fa114846bb80c3d488e41a186bce4894...
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
    git commit --allow-empty
Otherwise, please use 'git reset'
(...)
 Once everything’s at your taste, we can remove the relationship with the source
project and push the newly populated
   orphan
 branch upstream:
$ git branch -r -D code_import/develop
$ git push --force --set-upstream origin orphan
                        Kevin Deldycke.
Unless contrary mentioned, the content of this site is published
under a Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International license.                    

Disclaimer
All opinions expressed in this site are my own personal opinions and are not endorsed by, nor do they represent the opinions of my previous, current and future employers or any of its affiliates, partners or customers.
Feeds