WEB-03 GitHub

两个文档:

  • git documentation
  • atlassian git tutorial

Centralised vs Distributed
Subversion(SVN) => Git

  • Step 0: -set up your git
  git config --global user.name "<your-full-name>"
  git config --global user.email "<your-email-address>"
  git config --global color.ui auto
  git config --global merge.conflictstyle diff3
  git config --global core.editor "code --wait"
  • -setting up a repository
git init
git clone + 地址    clone该地址文件到本地

(shift+command +. 显示隐藏文件夹 ,看到.git)

  • 两步commit
git add .
git commit

commit changes

git rm(optional)     相当于remove file后 git add .   
git stash(important!)   相当于暂存在一个栈中
git stash pop  从栈中取出这个缓存

commit message

规范commit message
http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html
Header部分只有一行,包括三个字段:type(必需)、scope(可选)和subject(必需)。

(1)type
type用于说明 commit 的类别,只允许使用下面7个标识。

feat:新功能(feature)
fix:修补bug
docs:文档(documentation)
style: 格式(不影响代码运行的变动)
refactor:重构(即不是新增功能,也不是修改bug的代码变动)
test:增加测试
chore:构建过程或辅助工具的变动

(2)scope
scope用于说明 commit 影响的范围,比如数据层、控制层、视图层等等,视项目不同而不同。

(3)subject
subject是 commit 目的的简短描述,不超过50个字符。

以动词开头,使用第一人称现在时,比如change,而不是changed或changes
第一个字母小写
结尾不加句号(.)

Undo change

git在stage中发生变化

* git checkout  切换分支
* git clean 从你的工作目录中删除所有没有tracked过的文件
* git log:查看版本信息
* git revert :可以revert很久之前的版本
* git reset   :revert跨版本之前的版本必须删除中间的版本

Status and History

* git status: 当前状态
  
* git diff                    :working directory中的变化
  git diff --cashed  

* git log  :查看history
  git log --online --graph --all

细节:

const products =[
  'string',
  'string2',
];
  • 比如这里js文件自己在结尾多加个逗号,这样git计算更新代码比较准确

GitHub 常用指令

  • git status 现在git状态

  • git checkout 切换branch

  • git add . 更新所有文件(➕指定文件名就更新指定文件)

  • git reset

  • git revert

  • git log 打印git活动
    git log -p

  • git clean

  • git commit

  • git stash 暂存
    git stash pop
    查文档

https://www.atlassian.com/git/tutorials/comparing-workflows/feature-branch-workflow

https://www.endoflineblog.com/oneflow-a-git-branching-model-and-workflow

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

git branch 创建合并分支

master:
branch 1:test

  • git branch 创建branch
  • git add
  • git commit
  • git checkout 调节目前指针到某branch上去
    git branch -b:
  • git branch -d 删除branch
    git branch -d:已经merge或者push过的branch
    git branch -D:删除未merge的branch

semantic branch names

  • seat/feature
  • fix/bugfix/hotfix
  • chore

merge &rebase日常协作

  • merge


    image.png
  • rebase

Set up tracking branch

git branch -u <name>/<branch>
也可以在push的时候建立这种联系

Update local from remote

(remote tracking branch: 单纯一个指针,所有和远端产生联系的branch--origin/name)

  • git fetch
  • git pull 默认fetch所有branch
  • git push 默认不会fetch其他branch
    git push -u <name><branch>
    git push <name><local_branch>:<remote_branch> 一般工作中local_brach和remote_branch都会设为一样的

Delete a remote branch

  • git push -d <name><branch>
  • git push -u

两种workflow: merge and rebase

  • git rebase 把当前分支原点rebase到master(可以先这样再转到master去merge)
  • git merge 从master把分支master进来
git commit
git commit
git commit 

git branch test
git commit
git commit
git checkout test
git commit
git commit
git commit
git checkout 9fced1b
git branch test2
git commit
git checkout test2
git commit
git checkout test
git rebase test

Force push

git push -f
git push <name> +<branch_name>
git push --force-with-lease

Ask git to ignore files(.gitignore)

把一些不需要变化的东西放在.gitignore里

GitHub 团队协作

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容