Git

Git 提交规范

prefix description
feat A new feature
fix A bug fix
docs Documentation only changes
style Changes that do not affect the meaning of the code
refactor A code change that neither fixes a bug nor adds a feature
perf A code change that improves performance
test Adding missing tests or correcting existing tests
build Changes that affect the build system or external dependencies
ci Changes to our CI configuration files and scripts
chore Other changes that don’t modify src or test files
revert Reverts a previous commit

Git 常用操作记录

创建远端分支

1
 git push --set-upstream origin <branch-name>

删除远端分支

1
2
3
git push origin :<branch-name>
# 或者
git push origin --delete <branch-name>

从远程分支中创建并切换到本地分支

1
git checkout -b <branch-name> origin/<branch-name>

删除分支

1
git branch -D <branch-name>

重命名本地分支

1
git branch -m <new-branch-name>

交互式变基到指定记录

压缩commit记录

1
git rebase -i <commit-hash>

继续变基操作

1
git rebase --continue

修改 commit 注释信息

1
git commit --amend

撤销 commit 保留变动

1
git reset HEAD^ --minxed (默认参数)

撤销 commit 保留变动和 git add

1
git reset HEAD^ --soft

撤销 commit 并删除变动

1
git reset HEAD^ --hard

当前修改存储或取出到 stash

[see more]

1
git stash push/pop

清空所有的 commit

1
git update-ref -d HEAD

快速切换到上一个分支

1
git checkout -

关联远程分支

1
git branch -u origin/<branch-name>

展示本地分支关联远程仓库的情况

1
git branch -vv

从远程分支中创建并切换到本地分支

1
git checkout -b <branch-name> origin/<branch-name>

展示简化的 commit 历史

1
git log --graph --pretty=oneline --abbrev-commit
Last updated on 2023-03-19 21:23:50