4 How to do stuff with git
10 ##### Remove history of all but select files in cloned repo
15 $ git gc --aggressive --prune=now
16 $ git remote rm origin
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
27 $ git gc --aggressive --prune=now
30 ##### Remove history of previously-removed (not in current tree) files
32 $ git log --pretty=format: --name-status \
33 | awk '$0 != "" {print $2}' \
34 | sort -u > /tmp/tree.old
35 $ git ls-tree -r --name-only HEAD > /tmp/tree.new
39 grep -Fvxf /tmp/tree.new /tmp/tree.old \
40 | xargs git rm --cached -r --ignore-unmatch
46 Inserting a new root commit
47 ---------------------------
49 git checkout --orphan $TEMP_BRANCH
51 git commit --allow-empty -m $INIT_COMMIT_MSG
52 git rebase --onto $TEMP_BRANCH --root $MAIN_BRANCH
53 git branch -d $TEMP_BRANCH
57 Deleting all tags, locally and remotely
58 ---------------------------------------
63 git push $REMOTE_NAME :refs/tags/$tag
68 Get an older version of a file
69 ------------------------------
72 git cat-file -p $COMMIT_DIGEST:$FILE_PATH
79 From [docs](https://git-scm.com/docs/git-rebase#_splitting_commits):
81 - Start an interactive rebase with `git rebase -i <commit>^`, where `<commit>`
82 is the commit you want to split.
83 - Mark the commit you want to split with the action "edit".
84 - When it comes to editing that commit, execute `git reset HEAD^`. The effect
85 is that the HEAD is rewound by one, and the index follows suit. However, the
86 working tree stays the same.
87 - Now add the changes to the index that you want to have in the first commit
89 - Commit the now-current index with whatever commit message is appropriate now.
90 - Repeat the last two steps until your working tree is clean.
91 - Continue the rebase with `git rebase --continue`.
102 $ git remote add repo_A ../repo_A
103 $ git fetch repo_A --tags
104 $ git merge --allow-unrelated-histories repo_A/$BRANCH
105 $ git remote remove repo_A