写在前面
最近可能陆续会补一些以前学习时做的笔记吧,算是一个回顾,也是总结一下准备新的开始。
毕竟!再不学习!!就要废了!!!
git操作
我比较常用的一个工作流程大概是这样:
初始化一个git仓库
1 | // creates a new Git repository |
本地仓库修改提交
添加至暂存区1
2// adds files from the working directory to the staging area
git add
1 | git add . // 添加所有改变文件,任何未改变文件都不会被包含 |
查看状态1
2// inspects the contents of the working directory and staging area
git status
查看改动1
2// shows the difference between the working directory and the staging area
git diff
提交1
2// permanently stores file changes from the staging area in the repository
git commit
云端仓库
A remote is a Git repository that lives outside your Git project folder. Remotes can live on the web, on a shared network or even in a separate folder on your local computer.
云端建立分支1
git remote add origin git@github.com:username/repository.git
同步云端仓库1
2// push a local branch to the origin remote
git push -u origin master
这个流程一般是我在本地建好仓库后同步至github时的操作。还有一个常用的流程是从github克隆代码,然后本地修改上传。
克隆一个git仓库
1 | // Creates a local copy of a remote |
版本回退
查看提交纪录
1 | // shows a list of all previous comits |
查看云端项目
1 | // Lists a Git project's remotes. |
回退
1 | // backtrack in Git: |
git分支
Git branching allows users to experiment with different versions of a project by checking out separate branches to work on.1
2// Lists all a Git project's branches.
git branch
1 | // Creates a new branch. |
1 | // Used to switch from one branch to another. |
1 | // Deletes the branch specified. |
1 | // Used to join file changes from one branch to another. |
git协作流程
The Git Collaborative Workflow are steps that enable smooth project development when multiple collaborators are working on the same Git project.
The workflow for Git collaborations typically follows this order:
1.Fetch and merge changes from the remote1
2// Fetches work from the remote into the local copy.
git fetch
1 | // Merges origin/master into your local branch. |
2.Create a branch to work on a new project feature
3.Develop the feature on your branch and commit your work
4.Fetch and merge from the remote again (in case new commits were made while you were working)
5.Push your branch up to the remote for review