Created
January 23, 2012 13:21
-
Star
(126)
You must be signed in to star a gist -
Fork
(22)
You must be signed in to fork a gist
-
-
Save ssp/1663093 to your computer and use it in GitHub Desktop.
Revisions
-
ssp revised this gist
Jan 23, 2012 . 1 changed file with 24 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,35 +9,39 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem ### 1. copy the repository to extract the file from and go to the desired branch ```sh ➜ /tmp git clone git@github.com:ssp/pazpar2.git pazpar2g Cloning into pazpar2g... remote: Counting objects: 14950, done. remote: Compressing objects: 100% (4092/4092), done. remote: Total 14950 (delta 10938), reused 14719 (delta 10707) Receiving objects: 100% (14950/14950), 3.30 MiB | 1.60 MiB/s, done. Resolving deltas: 100% (10938/10938), done. ➜ /tmp cd pazpar2g ➜ pazpar2g git:(master) git checkout ssp Branch ssp set up to track remote branch ssp from origin. Switched to a new branch 'ssp' ``` ### 2. reduce the repository to just the subfolder »etc« which contains the interesting file(s) ```sh ➜ pazpar2g git:(ssp) git filter-branch --prune-empty --subdirectory-filter etc -- --all Rewrite b3d4f2a89fdee662fb43122990fc28aa2c08bee5 (558/558) Ref 'refs/heads/master' was rewritten Ref 'refs/heads/ssp' was rewritten Ref 'refs/remotes/origin/master' was rewritten WARNING: Ref 'refs/remotes/origin/master' is unchanged Ref 'refs/remotes/origin/ssp' was rewritten Ref 'refs/tags/wildcard-matching' was rewritten ``` ### 3. remove all files other than the ones you want to keep (tmarc.xsl, check-pazpar2.xsl) ```sh ➜ pazpar2g git:(ssp) git filter-branch -f --prune-empty --index-filter 'git rm --cached --ignore-unmatch $(git ls-files | grep -v "tmarc.xsl\|check-pazpar2.sh")' Rewrite f06a533323ad8257efa9e52c45ad2e22e2b09b1c (1/558)rm 'bibs.pz' … [lenghty output omitted] Ref 'refs/heads/ssp' was rewritten ➜ pazpar2g git:(ssp) ls -l total 48 -rwxrwxr-x 1 ssp ssp 1359 2012-01-23 14:03 check-pazpar2.sh -rw-rw-r-- 1 ssp ssp 41078 2012-01-23 14:03 tmarc.xsl ``` -
ssp revised this gist
Jan 23, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem ### 1. copy the repository to extract the file from and go to the desired branch ```sh ➜ /tmp: git clone git@github.com:ssp/pazpar2.git pazpar2g zsh: correct 'pazpar2g' to 'pazpar2' [nyae]? n Cloning into pazpar2g... remote: Counting objects: 14950, done. -
ssp revised this gist
Jan 23, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem ### 1. copy the repository to extract the file from and go to the desired branch ```sh ➜ /tmp git clone git@github.com:ssp/pazpar2.git pazpar2g zsh: correct 'pazpar2g' to 'pazpar2' [nyae]? n Cloning into pazpar2g... remote: Counting objects: 14950, done. -
ssp revised this gist
Jan 23, 2012 . 1 changed file with 14 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,19 +8,20 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem ### 1. copy the repository to extract the file from and go to the desired branch ```sh ➜ /tmp **git clone git@github.com:ssp/pazpar2.git pazpar2g** zsh: correct 'pazpar2g' to 'pazpar2' [nyae]? n Cloning into pazpar2g... remote: Counting objects: 14950, done. remote: Compressing objects: 100% (4092/4092), done. remote: Total 14950 (delta 10938), reused 14719 (delta 10707) Receiving objects: 100% (14950/14950), 3.30 MiB | 1.60 MiB/s, done. Resolving deltas: 100% (10938/10938), done. ➜ /tmp __cd pazpar2g__ ➜ pazpar2g git:(master) __git checkout ssp__ Branch ssp set up to track remote branch ssp from origin. Switched to a new branch 'ssp' ``` ### 2. reduce the repository to just the subfolder »etc« which contains the interesting file(s) ➜ pazpar2g git:(ssp) __git filter-branch --prune-empty --subdirectory-filter etc -- --all__ Rewrite b3d4f2a89fdee662fb43122990fc28aa2c08bee5 (558/558) -
ssp revised this gist
Jan 23, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem ### 1. copy the repository to extract the file from and go to the desired branch ➜ /tmp **git clone git@github.com:ssp/pazpar2.git pazpar2g** zsh: correct 'pazpar2g' to 'pazpar2' [nyae]? n Cloning into pazpar2g... remote: Counting objects: 14950, done. -
ssp revised this gist
Jan 23, 2012 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ # How to extract a single file with its history from a git repository These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and should performed on a copy of the original repository (1.). First the repository is reduced to just the subfolder containing the files in question using `git filter-branch --subdirectory-filter` (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository. Finally all remaining files are listed using `git ls`, the files to keep are removed from that using `grep -v` and the resulting list is passed to `git rm` which is invoked by `git filter-branch --index-filter` (3.). A bit convoluted but it does the trick. @@ -21,7 +21,7 @@ Finally all remaining files are listed using `git ls`, the files to keep are rem Branch ssp set up to track remote branch ssp from origin. Switched to a new branch 'ssp' ### 2. reduce the repository to just the subfolder »etc« which contains the interesting file(s) ➜ pazpar2g git:(ssp) __git filter-branch --prune-empty --subdirectory-filter etc -- --all__ Rewrite b3d4f2a89fdee662fb43122990fc28aa2c08bee5 (558/558) Ref 'refs/heads/master' was rewritten -
ssp created this gist
Jan 23, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ # How to extract a single file with its history from a git repository These steps show two less common interactions with git to extract a single file which is inside a subfolder from a git repository. These steps essentially reduce the repository to just the desired files and are performed on a copy (1.). Then the repository is reduced to just the subfolder containing the files in question using `git filter-branch --subdirectory-filter` (2.) which is a useful step by itself if just a subfolder needs to be extracted. This step moves the desired files to the top level of the repository. Finally all remaining files are listed using `git ls`, the files to keep are removed from that using `grep -v` and the resulting list is passed to `git rm` which is invoked by `git filter-branch --index-filter` (3.). A bit convoluted but it does the trick. ### 1. copy the repository to extract the file from and go to the desired branch ➜ /tmp __git clone git@github.com:ssp/pazpar2.git pazpar2g__ zsh: correct 'pazpar2g' to 'pazpar2' [nyae]? n Cloning into pazpar2g... remote: Counting objects: 14950, done. remote: Compressing objects: 100% (4092/4092), done. remote: Total 14950 (delta 10938), reused 14719 (delta 10707) Receiving objects: 100% (14950/14950), 3.30 MiB | 1.60 MiB/s, done. Resolving deltas: 100% (10938/10938), done. ➜ /tmp __cd pazpar2g__ ➜ pazpar2g git:(master) __git checkout ssp__ Branch ssp set up to track remote branch ssp from origin. Switched to a new branch 'ssp' ### 2. (if necessary) reduce the repository to just the subfolder etc which contains the interesting file(s) ➜ pazpar2g git:(ssp) __git filter-branch --prune-empty --subdirectory-filter etc -- --all__ Rewrite b3d4f2a89fdee662fb43122990fc28aa2c08bee5 (558/558) Ref 'refs/heads/master' was rewritten Ref 'refs/heads/ssp' was rewritten Ref 'refs/remotes/origin/master' was rewritten WARNING: Ref 'refs/remotes/origin/master' is unchanged Ref 'refs/remotes/origin/ssp' was rewritten Ref 'refs/tags/wildcard-matching' was rewritten ### 3. remove all files other than the ones you want to keep (tmarc.xsl, check-pazpar2.xsl) ➜ pazpar2g git:(ssp) __git filter-branch -f --prune-empty --index-filter 'git rm --cached --ignore-unmatch $(git ls-files | grep -v "tmarc.xsl\|check-pazpar2.sh")'__ Rewrite f06a533323ad8257efa9e52c45ad2e22e2b09b1c (1/558)rm 'bibs.pz' … Ref 'refs/heads/ssp' was rewritten ➜ pazpar2g git:(ssp) __ls -l __ total 48 -rwxrwxr-x 1 ssp ssp 1359 2012-01-23 14:03 check-pazpar2.sh -rw-rw-r-- 1 ssp ssp 41078 2012-01-23 14:03 tmarc.xsl