Add split repo cleaning steps.
[git-cheat-sheet.git] / README.md
... / ...
CommitLineData
1git-cheat-sheet
2===============
3
4How to do stuff with git
5
6
7Splitting a repo
8----------------
9
10### Remove history of all but select files in cloned repo
11```sh
12$ cp -Rp old new
13$ cd new
14$ git clean -dfx
15$ git gc --aggressive --prune=now
16$ git remote rm origin
17$ git filter-branch \
18 --prune-empty \
19 --index-filter '
20 git ls-tree -r --name-only HEAD \
21 | grep -v file_i_want_to_keep_1 \
22 | grep -v file_i_want_to_keep_.. \
23 | grep -v file_i_want_to_keep_n \
24 | xargs git rm --cached -r --ignore-unmatch
25 ' \
26 HEAD
27$ git gc --aggressive --prune=now
28```
29
30### Remove history of previously-removed (not in current tree) files
31```sh
32$ git log --pretty=format: --name-status | awk '$0 != "" {print $2}' | sort -u > /tmp/tree.old
33$ git ls-tree -r --name-only HEAD > /tmp/tree.new
34$ git filter-branch --prune-empty --index-filter 'grep -Fvxf /tmp/tree.new /tmp/tree.old | xargs git rm --cached -r --ignore-unmatch' HEAD
35```
This page took 0.014226 seconds and 4 git commands to generate.