git subtree - Detach (move) subdirectory into separate Git dépositaire

Mots clés : gitgit-subtreegit-filter-branchgit

meilleur 5 Réponses git subtree - Detach (move) subdirectory into separate Git dépositaire

vote vote

91

 cd <big-repo>  git subtree split -P <name-of-folder> -b <name-of-new-branch> 
 mkdir ~/<new-repo> && cd ~/<new-repo>  git init  git pull </path/to/big-repo> <name-of-new-branch> 
 git remote add origin <git@github.com:user/new-repo.git>  git push -u origin master 
 git rm -rf <name-of-folder> 
tree ~/node-browser-compat  node-browser-compat ├── ArrayBuffer ├── Audio ├── Blob ├── FormData ├── atob ├── btoa ├── location └── navigator 
cd ~/node-browser-compat/ git subtree split -P btoa -b btoa-only 
mkdir ~/btoa/ && cd ~/btoa/ git init git pull ~/node-browser-compat btoa-only 
git remote add origin git@github.com:node-browser-compat/btoa.git git push -u origin master 
git pull origin master git push origin master 
git rm -rf btoa 
brew install git 
sudo apt-get update sudo apt-get install git git --version 
sudo add-apt-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git 
sudo chmod +x /usr/share/doc/git/contrib/subtree/git-subtree.sh sudo ln -s \ /usr/share/doc/git/contrib/subtree/git-subtree.sh \ /usr/lib/git-core/git-subtree 
git filter-branch --prune-empty --tree-filter 'rm -rf <name-of-folder>' HEAD 
git log -- <name-of-folder> # should show nothing 
rm -rf .git/refs/original/ && \ git reflog expire --all && \ git gc --aggressive --prune=now  git reflog expire --all --expire-unreachable=0 git repack -A -d git prune 
vote vote

81

git clone /XYZ /ABC 
cd /ABC for i in branch1 br2 br3; do git branch -t $i origin/$i; done git remote rm origin 
cd /ABC for i in $(git branch -r | sed "s/.*origin\///"); do git branch -t $i origin/$i; done git remote rm origin 
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter ABC -- --all 
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter ABC HEAD 
git reset --hard git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d git reflog expire --expire=now --all git gc --aggressive --prune=now 
vote vote

72

git filter-branch --tree-filter "rm -rf ABC" --prune-empty HEAD 
vote vote

69

git clone --no-hardlinks foo bar; cd bar git filter-branch --subdirectory-filter subdir/you/want 
git remote rm origin git update-ref -d refs/original/refs/heads/master git reflog expire --expire=now --all 
git repack -ad 
vote vote

52

git clone --no-hardlinks file:///SOURCE /tmp/blubb cd blubb git filter-branch --subdirectory-filter ./PATH_TO_EXTRACT  --prune-empty --tag-name-filter cat -- --all git clone file:///tmp/blubb/ /tmp/blooh cd /tmp/blooh git reflog expire --expire=now --all git repack -ad git gc --prune=now 
!/bin/bash  if (( $# < 3 )) then     echo "Usage:   $0 </path/to/repo/> <directory/to/extract/> <newName>"     echo     echo "Example: $0 /Projects/42.git first/answer/ firstAnswer"     exit 1 fi   clone=/tmp/${3}Clone newN=/tmp/${3}  git clone --no-hardlinks file://$1 ${clone} cd ${clone}  git filter-branch --subdirectory-filter $2  --prune-empty --tag-name-filter cat -- --all  git clone file://${clone} ${newN} cd ${newN}  git reflog expire --expire=now --all git repack -ad git gc --prune=now 

Questions similaires