simon / Git

Last active 1 month ago

simon revised this gist 1 month ago · d60df4f

1 file changed, 63 insertions

git.md (file created)
@@ -0,0 +1,63 @@
1 + # git
2 +
3 + ### Sparse checkouts
4 +
5 + Useful when you only need a few files checked out in large repos
6 +
7 + ```javascript
8 + git clone -n --depth=1 --filter=tree:0 git@github.com:giantswarm/control-plane-catalog.git
9 + # add the directories you want to work in
10 + git sparse-checkout set --no-cone . oauth2-proxy-3.2.0.tgz-meta/
11 + # checkout the files
12 + git checkout -- oauth2-proxy-3.2.0.tgz-meta/
13 + # make changes, then stage them
14 + git add --sparse oauth2-proxy-3.2.0.tgz-meta/
15 + ```
16 +
17 +
18 + ***
19 +
20 + ### Search git history for a [string](stringhttps://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string))
21 +
22 + * [https://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string](stringhttps://stackoverflow.com/questions/4468361/search-all-of-git-history-for-a-string))
23 +
24 + ```javascript
25 + git log -S <string>
26 + ```
27 +
28 +
29 + ***
30 +
31 + ### Move commits from main to feature branch
32 +
33 + ```
34 + git checkout main
35 +
36 + git checkout <commit hash prior to the first one to move>
37 + git checkout -b feature_branch
38 +
39 + git rebase main
40 + # or
41 +
42 + git cherry-pick <commit hashes to move>
43 + git checkout main
44 +
45 + git reset --hard <commit hash used to create initial branch>
46 + ```
47 +
48 +
49 + ---
50 +
51 + ### Partially revert previous commit
52 +
53 + * Revert the commit without committing the change:
54 +
55 + ```javascript
56 + git revert -n <commit>
57 + ```
58 +
59 + * Edit the files to retain the changes manually, or select the hunks:
60 +
61 + ```javascript
62 + git add -p filename.ext
63 + ```