4 How to do stuff with git
6 Staging a subset of changes in a file
7 -------------------------------------
12 n - do not stage this hunk
13 q - quit; do not stage this hunk or any of the remaining ones
14 a - stage this hunk and all later hunks in the file
15 d - do not stage this hunk or any of the later hunks in the file
16 g - select a hunk to go to
17 / - search for a hunk matching the given regex
18 j - leave this hunk undecided, see next undecided hunk
19 J - leave this hunk undecided, see next hunk
20 k - leave this hunk undecided, see previous undecided hunk
21 K - leave this hunk undecided, see previous hunk
22 s - split the current hunk into smaller hunks
23 e - manually edit the current hunk
26 https://git-scm.com/docs/git-add#Documentation/git-add.txt-patch
32 ##### Remove history of all but select files in cloned repo
37 $ git gc --aggressive --prune=now
38 $ git remote rm origin
42 git ls-tree -r --name-only HEAD \
43 | grep -v file_i_want_to_keep_1 \
44 | grep -v file_i_want_to_keep_.. \
45 | grep -v file_i_want_to_keep_n \
46 | xargs git rm --cached -r --ignore-unmatch
49 $ git gc --aggressive --prune=now
52 ##### Remove history of previously-removed (not in current tree) files
54 $ git log --pretty=format: --name-status \
55 | awk '$0 != "" {print $2}' \
56 | sort -u > /tmp/tree.old
57 $ git ls-tree -r --name-only HEAD > /tmp/tree.new
62 grep -Fvxf /tmp/tree.new /tmp/tree.old \
63 | xargs git rm --cached -r --ignore-unmatch
69 Inserting a new root commit
70 ---------------------------
72 git checkout --orphan $TEMP_BRANCH
74 git commit --allow-empty -m $INIT_COMMIT_MSG
75 git rebase --onto $TEMP_BRANCH --root $MAIN_BRANCH
76 git branch -d $TEMP_BRANCH
80 Deleting all tags, locally and remotely
81 ---------------------------------------
86 git push $REMOTE_NAME :refs/tags/$tag
91 Get an older version of a file
92 ------------------------------
95 git cat-file -p $COMMIT_DIGEST:$FILE_PATH
102 From [docs](https://git-scm.com/docs/git-rebase#_splitting_commits):
104 - Start an interactive rebase with `git rebase -i <commit>^`, where `<commit>`
105 is the commit you want to split.
106 - Mark the commit you want to split with the action "edit".
107 - When it comes to editing that commit, execute `git reset HEAD^`. The effect
108 is that the HEAD is rewound by one, and the index follows suit. However, the
109 working tree stays the same.
110 - Now add the changes to the index that you want to have in the first commit
112 - Commit the now-current index with whatever commit message is appropriate now.
113 - Repeat the last two steps until your working tree is clean.
114 - Continue the rebase with `git rebase --continue`.
125 $ git remote add repo_A ../repo_A
126 $ git fetch repo_A --tags
127 $ git merge --allow-unrelated-histories repo_A/$BRANCH
128 $ git remote remove repo_A