git usage


shallow clone

root@n1:/usr # git clone -o freebsd -b main --depth 1 https://github.com/freebsd/freebsd-src.git src

root@n1:/usr # git clone -o freebsd -b stable/14 --depth 1 https://github.com/freebsd/freebsd-src.git src

find remote URL

% git remote show origin

cherry pick a commit

% git cherry-pick -x commit_xxx --edit

apply a patch

cc@s1:/usr/src % sudo git apply --stat ~/patch.diff 
 sys/conf/options      |    3 +
 sys/netinet/ip_icmp.c |  142 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 145 insertions(+)

cc@s1:/usr/src % sudo git apply --check ~/patch.diff 
cc@s1:/usr/src % sudo git reset --hard stable/14
cc@s1:/usr/src % sudo git am --abort
cc@s1:/usr/src % sudo git apply ~/patch.diff 

create a tar ball

## the branch name `main` can be replaced with a specific commit or branch/tag
git archive --format=tgz -o /proj/src.tgz --prefix=src/ main

get more code context

# git diff -U10
# git log -p -U10

chengcui/git (last edited 2025-03-06T15:40:58+0000 by chengcui)