tags: git
202103
[toc]
说明介绍
功能模块
Git 创建分支
1 2 3 4 5 6
| git branch name 创建分支 git checkout branch_xxx git add aaa git commit -m "sss" aaa git push origin branch_xxx
|
git config 配置
1 2 3 4 5 6 7 8 9
| git config --list
git config --global user.name xxx
git config --global --unset user.name
|
git 存储用户密码
user 中存储用户信息 , credential 存储密码(第一次 push 需要输入)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = http://192.168.200.130/crawler/tongshuncha/hive/data_check.git fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master
[user] name = xxxx email = xxxxx@qq.com [credential] helper = store
|
.gitignore 忽略文件
忽略规则语法:
- 空格不匹配任意文件,可作为分隔符,可用反斜杠转义
#
开头: 标识注释,可以使用反斜杠进行转义
!
开头: 标识否定,该文件将会再次被包含,如果排除了该文件的父级目录,则使用 ! 也不会再次被包含。可以使用反斜杠进行转义
/
结束: 只匹配文件夹以及在该文件夹路径下的内容,但是不匹配该文件
/
开头: 匹配文件
- 如果一个模式不包含斜杠,则它匹配相对于当前 .gitignore 文件路径的内容,如果该模式不在 .gitignore 文件中,则相对于项目根目录
**
匹配多级目录,可在开始,中间,结束
?
通用匹配单个字符
[]
通用匹配单个字符列表
常用忽略命令
1 2 3 4 5 6 7 8
| $ git check-ignore -v a.zip .gitignore:4:*.zip a.zip
git rm -r --cached . git add . git commit -m 'update .gitignore'
|
Python 项目 .gitignore
文件样例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| *.pyc **/__pycache__/ logs/ *.log *.zip
bin/ : 忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件 /bin : 忽略根目录下的bin文件 /*.c : 忽略 cat.c,不忽略 build/cat.c debug/*.obj : 忽略 debug/io.obj,不忽略 debug/common/io.obj 和 tools/debug/io.obj **/foo : 忽略/foo, a/foo, a/b/foo等 a/**/b : 忽略a/b, a/x/b, a/x/y/b等 !/bin/run.sh : 不忽略 bin 目录下的 run.sh 文件 *.log : 忽略所有 .log 文件 config.php : 忽略当前路径的 config.php 文件
|
Git 仓库忽略提交规则 & .gitignore 配置
Git 修改历史 commit 信息
1 2 3 4 5 6 7 8 9
| git log
git show
git show commitId
git commit --amend
|
修改前 n 次 commit 的提交信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| $ git rebase -i HEAD~n
pick 6608e22 修改代码结构调整导致不能正常显示的问题 pick 1d381cd 菜单切换可用 ...
$ git commit --amend
$ git rebase --continue
git commit --amend --author="user <user@qq.com>" --no-edit git commit --amend git rebase --continue
git rebase -i --root
|
GIT 分支变主干
1 2 3
|
git push origin origin/develop:master -f
|
git 版本回退
Git 代码回退
git 标签
1 2 3 4 5 6 7 8 9 10 11 12 13
| git tag
git tag -a v1.0.0 -m "内容: v1.0.0"
git show v0.0.6
git push origin v1.0.0
git tag -d v1.0.0
git push origin :refs/tags/v1.0.0
|
github 迁移到 GitLab
github 仓库迁移到 gitlab
Git 注释规范
提交格式:
1 2 3 4 5 6
| <type>(<scope>): <subject> // 空一行 <body>
范例: fix
|
提交的具体情况
type(必需): 用于说明 commit 的类别
- br: 此项特别针对 bug 号,用于向测试反馈 bug 列表的 bug 修改情况
- feat: 新功能(feature)
- fix: 修补
- docs: 文档(documentation)
- style: 格式(不影响代码运行的变动)
- refactor: 重构(即不是新增功能,也不是修改 bug 的代码变动)
- test: 增加测试
- chore: 其他的小改动. 一般为仅仅一两行的改动, 或者连续几次提交的小改动属于这种
- revert: feat(pencil): add ‘graphiteWidth’ option (撤销之前的 commit)
- upgrade: 升级改造
- bugfix: 修补 bug
- optimize: 优化
- perf: Performance 的缩写, 提升代码性能
- test: 新增测试用例或是更新现有测试
- ci:主要目的是修改项目继续完成集成流程(例如 Travis,Jenkins,GitLab CI,Circle)的提交
- build: 主要目的是修改项目构建系统(例如 glup,webpack,rollup 的配置等)的提交
scope(可选)
- scope 用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。
subject(必需):
subject 是 commit 目的的简短描述,不超过 50 个字符。
以动词开头,使用第一人称现在时,比如 change,而不是 changed 或 changes
第一个字母小写
结尾不加句号(.)
<body>
(可选)
部分是对本次 commit 的详细描述,可以分成多行
常用命令
Git 常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| git add 添加修改文件 git status 查看状态(查看工作区文件状态) git checkout – file 丢弃工作区的修改 git commit -m "填写备注"提交修改到本地仓库 git merge 合并分支 git pull 拉取远程仓库版本 git push 推送本地仓到远程仓 git reset --hart HEAD^ 版本回退 git log 查看commit历史记录 git reflog 查看历史命令 git branch name 创建分支 git branch 查看分支 git checkout name 切换分支 git checkout -b name 创建+切换分支 git branch -D name 删除分支 git merge 分支 合并分支
|
git 简单使用
参考资源
https://blog.csdn.net/YJG7D314/article/details/104551896
https://blog.csdn.net/qq_38111015/article/details/84885809
https://blog.csdn.net/qq_36150631/article/details/81038485
Git 常用脚本
使用脚本
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 28 29 30
| git_init(){ git remote rm origin git remote add origin git@github.com:fansichao/code.git }
git_daily(){ git pull git add * git commit -m "定时提交" -a git push -u origin master }
Daily(){ source ~/env/bin/activate git_daily
}
Daily
|