Git是目前世界上最先进的分布式版本控制系统(没有之一)。
通俗:管理项目代码,记录每一处的变动
简单演示Git的作用
- 演示diff
- 历史变动
- 追踪改动人员
- Git History
- Git Graph
- GitLens
注:先演示命令行,再演示GUI插件效果
git init修改一些文件看看
git status- 本地修改->工作区
- 提交本地修改->暂存区
- 提交暂存区的内容->版本库
工作区默认和暂存区的内容进行比较
暂存区:
git add filename
git add *git diff filenamegit commit -m "msg"[
{
value: 'WIP',
name: '💪 WIP: Work in Progress',
},
{
value: 'feat',
name: '✨ feat: A new feature',
},
{
value: 'fix',
name: '🐞 fix: A bug fix',
},
{
value: 'refactor',
name: '🛠 refactor: A code change that neither fixes a bug nor adds a feature',
},
{
value: 'docs',
name: '📚 docs: Documentation only changes',
},
{
value: 'test',
name: '🏁 test: Add missing tests or correcting existing tests',
},
{
value: 'chore',
// prettier-ignore
name: '🗯 chore: Changes that don\'t modify src or test files. Such as updating build tasks, package manager'
},
{
value: 'style',
// prettier-ignore
name: '💅 style: Code Style, Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)'
},
{
value: 'revert',
name: '⏪ revert: Revert to a commit',
},
],git loggit reflog会退到最近的一次 commit 或者 add
git checkout -- filename# 变动内容会回到暂存区
git reset HEAD^
git reset --hard HEAD^通过git reflog查询回退前的commitId
git reset --hard commitId多人协同,离不开分支的支持
不同人在不同的开发分支上进行工作,开发完成后将内容汇入主分支或公共开发分支
通常开发分支前缀
{
"prefixes": [
"feature",
"fix",
"hotfix",
"release"
],
}创建
git branch newBranchName切换
git checkout otherBranchName创建并切换
git checkout -b newBranchName- 此时可能会遇到冲突的问题,冲突会导致无法合并
- 出现冲突的情况有很多种,这里不一一列举,大家后续遇到问题,利用搜索引擎解决
- 造成冲突的原因往往也是由于不规范的开发方案导致的
- 开源协作社区
- 提供Git仓库托管服务
- 提供邮箱就行
git add remote remoteUrlgit push -u originName branchName
# 等价于
git push --set-upstream originName localBranch:remoteBranch创建并更新本地远程分支
git fetchgit pullgit pull originName remoteBranch:LocalBranch以GitHub为例
- git stash
- git tag
- 提交PR