git 基础。git 101
THIS IS A WORK IN PROGRESS
overview of untracked files and changed files
1
2
3
4
> git status --branch --short
## main...origin/main
M 2024-05-10-git-101.md
?? bb
overview of staged changes
1
2
3
4
> git diff --stat --staged
_posts/2024-05-10-git-101.md | 15 +++++++++++++++
_posts/bb | 1 +
2 files changed, 16 insertions(+)
stage/unstage files
Replace reset
with add
to stage files.
1
2
3
> git reset ${path}
Unstaged changes after reset:
M _posts/2024-05-10-git-101.md
stage/unstage some lines in a file
Do this in an editor.
view git history of some lines in a file
Use the -L
option of log
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> git lg -- .\2022-06-05-debug-101.md
* 097a0bf - (li6in9muyou 1 year, 2 months ago) fix: htmlproofer disagree with unicode paths
* 8074d12 - (li6in9muyou 1 year, 2 months ago) chore: linting
* cf1678d - (li6in9muyou 1 year, 2 months ago) chore: update image links
* 423a881 - (li6in9muyou 1 year, 2 months ago) chore: linting with prettier
* 5d28c97 - (li6in9muyou 1 year, 2 months ago) fix: html-proofer errors
* 900fa15 - (li6in9muyou 1 year, 7 months ago) add chinese title for all posts
> git lg -L'14,18:.\2022-06-05-debug-101.md' -s
* 097a0bf - (li6in9muyou 1 year, 2 months ago) fix: htmlproofer disagree with unicode paths
* cf1678d - (li6in9muyou 1 year, 2 months ago) chore: update image links
* 423a881 - (li6in9muyou 1 year, 2 months ago) chore: linting with prettier
* 5d28c97 - (li6in9muyou 1 year, 2 months ago) fix: html-proofer errors
* fec61e0 - (li6in9muyou 1 year, 7 months ago) linting: prettier
* 5958d6d - (Li6q 1 year, 11 months ago) posts: migrate posts
diff and apply
Pipe anything from git diff
into any path.
Then use git apply --verbose ${patch_path} --directory ${prepend_directory}
to apply that patch. Paths in patch files are relative to .git
. Use --directory
option to adjust paths.
download git submodule dependencies
- call
sync
to copy.gitmodules
to.git/config
- update
.git/config/config
if needed - call
update
to download submodules
1
2
3
> nvim .gitmodules
> git submodules sync
> git submodule update --remote --recursive --init
download one branch and limited commits
Use --branch
and --depth
for faster cloning when all you want is to submit a pull request or read the code.
1
> git clone --branch main --depth=3 https://github.com/li6in9muyou/li6in9muyou.github.io.git
If another branch is needed
1
2
3
> git remote set-branches origin gh-pages
> git fetch origin gh-pages
> git checkout -b gh-pages FETCH_HEAD
本文由作者按照 CC BY 4.0 进行授权