Comments (16)
粒度划分
细粒度
以"完成"以下任意一项
- 某一项功能 或 代码段
- 添加必要文件/更改目录结构 + 更新必要配置
- 修改所有需要改正的字段/话述
独立
- 每个提交不应该包含跟它的comment无关的变更, 即描述要覆盖所有变更(细粒度的变更更容易描述, 但<细粒度.3>要满足)
- 不依赖"第三方分支": merge/rebase操作, 不应对除master, release, dev(develop), raw 之外的第三方分支使用. 项目成员分支间的依赖不应该存在, 即在合并到raw(develop)上之前是不能相互merge/rebase的
commit/comment
[<jira-id>: ]<动作类型>: [<模块/文件/功能等逗号分隔>:]+ <简要说明>
动作类型: Add, Rmv, Mdf, Dbg, Opt
模块/文件/功能
简要说明
# 实例
# ": "是英文标点加空格
# 尽量使用原有的词汇, 不要直接翻译成中文
Add: login: logo文件
Mdf: login: footer 配色 和 文案
Rmv: user: 无用的大尺寸图片
SHARP-1008: Dbg: login, user: style: sass文件除虫
SHARP-1009: Opt: profile:
from blog.
命令
- init
- add
- commit
- pull
- push
- rebase
- merge
- checkout
- cherry-pick
- reset
- stash
- remote
- branch
from blog.
git init
此命令自不必说, 在本"目录"[pwd]初始化一个代码仓库(repo), 最好第一个提交仅仅包含.gitignore
README
等初始化文件.
e.g. 如果远程有一个空仓, 比如在github上创建了一个repo2, 要把新创建的本地仓库推送到远程仓库:
- 就得设置
remote
, 即git remote add <repo2-alias> <repo2-uri>
- 并且还要设置
up-stream
, 即git push -u <repo2-alias> <repo2-branch-name>
from blog.
git add
该命令两种功能:
- 追踪新的文件
- 把新的变更放入暂存区
配合 git commit
命令使用
from blog.
git commit -m '<comment>'
该命令用于提交代码: 将暂存区中的新文件和新的变更提交到本地仓库中
-m 参数用于引导添加"提交说明(commit comment)" 已经在上文commit/comment中详细描述
from blog.
拉取代码git pull
, git pull --rebase
该命令用于从远程仓库拉取代码到本地, 默认当前分支, 还可以加参数git pull <repo2-alias> <repo2-branch-name>
来拉取对应分支
git pull --rebase
在拉取远程分支的时候还顺便处理rebase, 而非merge
from blog.
推送代码 git push
, git push <repo2-alias> <repo2-branch-name>
推送分支到远程服务器
- 可以指定远程仓库名和分支
git push <repo2-alias> <repo2-branch-name>
- 慎重! 慎重! 慎重! 可以加参数
-f
: 前提是这个一定不是master/release/raw/develop, 而是个人的分支或临时分支
from blog.
合并 git merge
不多说了, 废柴操作~
from blog.
git checkout
功能
- 切换当前分支为:
git checkout <branch-name>
, 另外可以用 -b 参数来检出制定提交为新分支git checkout <commit-id> -b <new-branch-name>
- 移动HEAD到对应的提交点
git checkout <commit-id>
- 用以还原文件: 从上一次的提交点里恢复文件, 覆盖当前的修改
git checkout -f <fileName>
git checkout -p <pathOfFolder>
from blog.
git reset -- <file-names>
from blog.
遴选 git cherry-pick <commit id>
这个功能相当有意思, 能把某个指定的提交点作为补丁添加到当前分支的最前端.
使用场景很单调: 把合格的提交点摘取到重要的分支上.
e.g. 我把自己的3个提交在我自己的分支 xvno 上rebase-squash成了一个提交点 mixed, 切换到develop
分支上后, 直接git cherry-pick <mixed: commit-id>
from blog.
合并/摘选 指定提交点, 变基到指定分支/提交点 git rebase -i <commit id>
, git rebase --continue
一般用于合并提交点
git的神器之一 rebase
, 无出其右者, 加上-i
之后, 就可以修改提交comment + 合并提交点 + 丢掉提交点...
添加--continue
之后, 能让暂停的rebase过程继续
from blog.
藏私房代码的地方 git stash push/pop/list/clear/apply
stash: 藏匿处, 暗格;
git stash
可以把已经 git add
的变更移动到暗格里. 应用场景:
- A. 当我们正在做一个功能点的开发,
- B. 突然接到一个紧急的新需求. 此时我们需要新开个分支来完成, 但当前代码还是比较弱智(即不满足粒度划分要求)而不能作为一个提交点,
- C. 这种情况下可以先把当前的变更
git add .
+git stash
然后处理新需求; - D. 当新需求已经处理完了, 我们需要回到 A点, 用
git stash list
查看曾经私藏了哪些代码, 并用git stash pop [sn]
来取回, 或者用git stash apply [sn]
来复制一份代码到当前工作环境, 这样就可以继续中断的工作了,
from blog.
远程仓库 git remote
做什么用?
- 本地仓库关联了哪些远程仓库,
git remote -v
- 添加远程仓库,
git remote add <repo-name> <repo-uri>
有了remote, 就可以光明正大的 git push <repo-name> <branch-name>
了
from blog.
分支管理 branch
git branch
参数 r
表示 remote-tracking
- 检出新分支
-avr
, 查看分支-dDr
, 删除分支
真正删除远程分支的方式 git push <repo-name> :<branch-name>
git checkout -b
就当前提交点新建一个分支
git checkout -b newbie
from blog.
实例演示
用1个实例演示日常工作流程
已经推送新建的本地仓库到github
- 调研需求, 并切换到目标分支, 拉取最新代码
- 从当前提交点检出新的分支, 并在该分支上开发
- 紧急任务来了, 我要优先处理
- 我是谁, 我从哪里来, 我要干什么?
- 我做完了, 得合并细小提交
- 我还得把开发结整合到master上, 并删掉当前分支
- todo列表上的下一个项目来了
- 这是一个循环
from blog.
Related Issues (20)
- HTML: JS: meta-viewport HOT 1
- JS: snake case & camel case HOT 1
- Docker: WordPress, Nginx HOT 2
- Nuxt: [BABEL] Note: The code generator has deoptimised the styling of XXX.js as it exceeds the max of 500KB. HOT 1
- Nginx: Tips HOT 2
- Shell: Tips HOT 1
- Nacos: Tips HOT 2
- Xnix: LVM: Tips
- OS: Ubuntu: apt HOT 1
- OS: Ubuntu: xclip HOT 3
- OS: Ubuntu: user HOT 1
- OS:Ubuntu: Nvidia GPU HOT 5
- OS: Ubuntu: CUDA
- OS:Ubuntu:zshconfig
- Web: blogs
- Network: tools: curl
- PL: node.js: egg.js HOT 2
- FFMPEG: ProRes HOT 1
- Networking: 阿里云: 云解析DNS HOT 3
- Shell: scripts HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.