| title | Git |
|---|---|
| sidebar | true |
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxygit remote add origin <url>git branch -agit branch -vv# 复制远程分支到本地且切换到该分支
git checkout -b develop origin/develop
# 切换到本地已有分支
git checkout develop# 删除本地分支
git branch -d <BranchName>
# 删除远程分支
git push origin :<BranchName>其他小伙伴删除了远程分支,但自己本地还存在远程分支的跟踪,使用删除远程分支的命令会报错,应采用如下命令
# 逐个删除
git branch --delete --remotes <Remote>/<BranchName>
git branch -dr <Remote>/<BranchName>
# 一次删除所有远程已删除的跟踪
git remote prune <Remote>git mv <oldname> <newname>git remote -vgit branch -m <newBranchName>git remote remove origingit remote rename origin destination方法一:
git update-ref -d HEAD
# 重设第一个 commit
git commit
# 强制推送到远程仓库
git push -f -u <Romote> <Branch>方法二:
# 1. 新建分支且无任何 commit 信息
git checkout --orphan latest_branch
# 2. 初始 commit
git add -A
git commit -am "Initial"
# 3. 删除原有分支 master
git branch -d master
# 4. 重命名当前分支为 master
git branch -m master
# 5. 强制推送到远程分支
git push -f origin mastergit add <filename> -p该命令每一处修改都问询问你是否提交
git stash push -m "stash message" <filePath>git stash -p# 打标签
git tag -a "v1.0.0"
# 删除标签,和删除分支一样
git push <Remote> :<Tag># 仅显示单行注释信息
git tag -ln
# 显示多行注释信息
git tag -ln<number> # 如显示3行:git tag -ln3git log --pretty=oneline --graphgit log branch-a ^branch-b可用来查看 branch-a 是否已经合并到 branch-b
# 删除已提交的文件夹:.github
git rm --cached -r .github
# 编辑 .gitignore 添加忽略
# .github首先在工作目录新建 .gitconfig,假设路径为 ~/company/.gitconfig
[user]
name = Another Name
email = another@mail.com修改用户目录下的配置(~/.gitconfig),增加如下:
[user]
name = Jun
email = jun@mail.com
[includeIf "gitdir/i:~/company/"]
path = ~/company/.gitconfig此时,全局 user.name 默认为 Jun,~/company/ 目录下为 Another Name
Git 提交信息技巧。
git commit -m "<word>: <描述>"
如:
git commit -m "Fix: 修复了很牛逼的 Bug"
参考 Angular 提交规范
| word | 场景 |
|---|---|
| Initial | 初始化 |
| Fix | 修复 |
| Feat(Feature) | 新功能 |
| Test | 测试用例 |
| Remove | 移除 |
| Revert | 还原 |
| Perf(Performance) | 优化提升 |
| Style | 格式,不影响代码运行 |
| Docs(Document) | 文档 |
| CI | 自动构建 |
| Upgrade | 升级 |
| Downgrade | 降级 |
| Refactor | 重构,不是修复 BUG,也不是添加功能 |
git log --format='%aN <%aE>' | LC_ALL=C.UTF-8 sort -uf > AUTHORS
