Download and install:
https://git-scm.com/download/win
Double-click the installation, the next step, the next step ...
User configuration information (Zibaojiamen) (git-bush in the configuration may be in cmd):
git config --global user.name "zhangsan"
git config --global user.email "[email protected]"
(Global parameters: All warehouses on this machine are using this configuration)
(Git config --list: View configuration information)
Visualization tools source tree installed:
https://www.sourcetreeapp.com/
Double-click the installation, the next step, the next step ...
Create a git repository:
Initializing the repository
git init
Add files to the repository
git add
git commit
(Not to the remote repository, you also need git push command)
Check warehouse status:
git status
Workflow Demo:
Into the working directory, execute the clear command (after clean up, this is a new directory)
New file and writes content:
View status:
Add files to the staging area, view the status:
Submitted to the local repository:
git commit -m "first commit"
Then, the product manager temporary change requests, change the next:
Just made changes, to be submitted to the staging area, otherwise, there is no local modified records:
git add test.txt
(然而,还没有进行自测,到这步,拎包走人)
在commit到本地仓库之前,产品经理pao过来说:修改不需要了。所以,要回滚到上那次:
(暂存区的修改回归到工作区。但工作区还没有弄干净clean)
通过git checkout命令将工作区的文件弄干净
在git checkout命令执行之前,先看下test.txt的内容:
执行完git checkout命令后:
(干净的)
接下来,又修改了代码:
再添加到暂存区,然后提交到本地仓库
接下来,产品经理说:第二次需求其实不要做,需要回滚到第一次
查看git提交日志:
回滚到第一次提交:
(进行回滚,--hard说明最终仓库和暂存区文件都回滚到第一次提交)
现在,又变回了第一次提交后的状态:
这时候,产品经理很欠抽的说:其实大家做的这么多都不用做的!你们要把本地仓库清理干净:
(本地清空了,但暂存区和本地仓库没有)
git commit之后才说明清空了:
提交到远程github:
先要创建ssh key:
在git-bash运行命令 ssh-keygen.exe -t rsa -C "[email protected]"(自己的git邮箱):
其实是保存在了git的家目录:
查看生成的公钥:
将公钥粘贴到github:
测试是否是通的:
添加远程仓库:
主要用这几个命令:
git remote add origin [email protected]:xxoo/xxoo.git
git pull origin master --allow-unrelated-histories
git push -u origin master
先在github上创建新的仓库:
然后在git-bash执行相关操作:
先进入工作目录:
创建并写入README.md文档:
初始化仓库:
git init
添加到暂存区:
git add
添加到本地仓库master分支
git commit -m "first commit"
本地仓库与远程github关联起来:
git remote add origin [email protected]:xxoo/websocket_push.git
推到github上:
查看github,会发现已经提交上来了:
改一下,再次提交:
(第一次git push -u origin master,接下来就可以git push)
查看github,已经更新了:
克隆仓库:
命令:
git clone [email protected]:xxoo/xxoo.git
测试:
标签管理:
命令:
git tag——>查看所有标签
git tag name——>创建标签
git tag -a name -m "commet"——>指定提示信息
git tag -d name——>删除标签
git push origin name——>标签发布
演示:
查看标签:
分支管理:
假设现在有个场景,你准备开发一个新功能,但需要两周时间才能完成,但只写了50%代码,如果立即提交,由于代码没有写完,不完整的代码可能导致项目运行出问题。但如果想把所有的代码写完,再一次提交,就会存在丢失每天进度的风险,有了分支就不用担心这个问题了。你只要创建属于你自己的分支,别人看不到,你只要在自己的分支上工作。而在自己的分支上,怎么提交都行。当你写完之后再合并到原来分支,这样既安全,又不影响工作。
演示:
(ls -a查看,没有看到.git文件,说明没有仓库)
创建新的分支(git branch):
查看分支:
(*说明在什么分支上)
切换到分支:
Based on the current branch, code editor:
The new code merged into the master branch up:
(To switch to the master branch)
Merge up to master:
Continue to write the code, find the branch feature_x has no use, this time we should be deleted branches of:
to sum up: