a guest Oct 23rd, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Steps for extracting files from one git repo into another:
  3. 0. Grab a copy of the utils files from this gist (and ensure they're marked as executable)
  4. 1. Clone the original repo to a new location: `git clone $ORIGINAL /tmp/new-repo && cd /tmp/new-repo`
  5. 2. Break the connection from the original repo: `git remote remove origin`
  6. 3. Create a branch of the starting point for easy reference
  7.    (git will actually do this for you, however I personally find it easier
  8.    to work with filter-branch if I have my own branches for various states):
  9.    `git branch original`
  10. 4. Work out which files you want to keep and adapt the `` suitably (see comment inside it)
  11.    Note: think about whether you want to keep things like the repo `README`, `LICENCE`, `.gitignore`, `.circleci/`
  12.    etc. in addition to the actually interesting files. Often these are useful to keep too!
  13. 5. Run filter branch:
  14.    `git filter-branch --prune-empty --force --index-filter /path/to/ --parent-filter /path/to/rewrite-common-parents.rb HEAD`
  15. 6. Check that you're happy with the files you have in the new repo. If you find
  16.    that there are some you're missing, reset (`git reset --hard original`) and
  17.    then go again from step 4.
  18. 7. Do any other manual tidyup you need to do (update the `README`, etc.)
  20. Notes:
  21.  * You _can_ put the filter scripts in the repo directory, however if they happen to conflict
  22.    with names of anything in the repo (at any point in history), then weirdness could result.
  23.  * The paths to the filter scripts need to be specified as absolute paths. I'm not entirely sure
  24.    why, but `git` errors if you do otherwise. Using `$PWD` is an easy way to achieve this if
  25.    you're being lazy (note that `./` does _not_ work).
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand