Git 相关备忘。
Add 1 2 git stash push /path/to/file
DIFF 1 2 3 4 git diff HEAD^^ HEAD main.c git diff HEAD^^..HEAD -- main.c git diff HEAD~2 HEAD -- main.c
标签 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 git tag git tag -l "<tagname>" git show <tagname> git tag <tagname> git tag -a <tagname> -m "<commit_info>" git tag -a <tagname> <commit_id> -m "<commit_info>" git push origin <tagname> git push origin --tags git tag -d <tagname> git push origin :refs/tags/<tagname> git push origin --delete <tagname> git push -d $(git tag -l "tag_prefix*" ) git tag -d $(git tag -l "*v3.[2]*-beta*" ) git tag -d $(git tag -l v0.2.[0-5]) git checkout <tagname> git checkout -b <branch> <tagname>
注意:①会使仓库处于 “分离头指针(detached HEAD)” 的状态,在 “分离头指针” 状态下,如果做了某些更改然后提交它们,标签不会发生变化, 但新提交将不属于任何分支,并且将无法访问,除非通过确切的提交哈希才能访问。 因此,如果你需要进行更改,比如要修复旧版本中的错误,那么通常需要『从tag创建新分支』。
分支 1 2 3 4 5 6 7 git checkout -b <new_branch_name> <tag_name> git rebase --continue git push -d origin <branchname> git branch -d <branchname>
提交 1 2 3 4 5 6 7 8 9 10 11 12 git commit --amend -m "new_message" git push --force repo_name branch_name git push --force-with-lease repo_name branch_name git rebase -i HEAD~3 pick => reword, save & close type new message, save & closegit push --force
Token
Fetch Folk 1 2 3 4 5 6 7 8 9 git remote -v git remote add upstream https://github.com/otheruser/repo.git git fetch upstream git branch -va git checkout main git rebase upstream/main git merge upstream/main
LargeFile 1 2 3 4 5 6 7 8 9 git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all rm -rf .git/refs/original/ git reflog expire --expire=now --all git gc --prune=now git gc --aggressive --prune=now git push --all --force
Version <major>.<minor>.<patch>-beta.<beta> == 1.2.3-beta.2
1 2 3 4 5 6 7 8 9 10 ~version ^version version >version >=version <version <=version 1.2.x * latest