blob: 2dcf2a1264a5486dff6312532dd30c6962d0634b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
Git Version Control
===================
## Scattered Shallow Clone
How to clone minimally required commits to have a working repo. VERY handy if
we just need to diff two refs from a GIANT repo where we do not have a local
copy of.
Basic setup:
mkdir MyTinyClone
cd MyTinyClone
git init
git co --orphan empty
git commit --allow-empty -m "Empty commit where our HEAD can stay to reduce unwanted disk IO"
git tag empty empty
git co --detach
git br -D empty
Seek what we wanna download:
git remote add origin ssh://example.com/repo.git
git ls-remote origin | grep whatever
Fetch only EXACTLY the branches we want (for example using previous output to
decide):
git fetch origin --depth=1 refs/heads/the-branch
git br the-branch FETCH_HEAD
Usually tags are of special interest in such a clone (note how we specify it
twice with colon in between):
git fetch origin --depth=1 refs/tags/v1.2.3:refs/tags/v1.2.3
## History digging for specific file
git log --follow -- path/to/file
## History search for file contents
Commit message contains: git log --grep foo
git log -S foo File contents "foo" (literal) num occur has changed:
git log --pickaxe-regex foo File contents "foo" (regex) num occur has changed:
git log -G foo Diff contains "foo" (regex):
For "-G" add "--patch" to get diff in place of ref.
[src](https://stackoverflow.com/a/1340245/4415884)
## Auto-destroy code-format
&& REMOTENAME=upstream \
&& BRANCH= \
&& ISSUENR= \
&& if test -n "$(git status --porcelain)"; then echo "working tree not clean" && false; fi \
&& git detach \
&& mvn spotless:apply \
&& git add -- . && git commit -m "[${ISSUENR:?}] Auto-destroy code-format" \
&& git l2 \
&& printf '\nTODO git br %s HEAD\n\n' "${BRANCH:?}" \
&& printf '\nTODO git push %s HEAD:%s\n\n' "${REMOTENAME:?}" "HEAD:${BRANCH:?}" \
## Reduce local disk usage
Source: "https://gitbetter.substack.com/p/how-to-clean-up-the-git-repo-and"
git remote prune origin
git repack
git prune-packed
git gc --aggressive
Sometimes also helpful. WARN reflog will be useless after that. Pass -n to see
what gets deleted:
git prune
|