summaryrefslogtreecommitdiff
path: root/doc/note/git/git.txt
blob: d0325a1a6e81255b7f8805467492b57826c8c858 (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

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


## 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