And examples of the use of basic git

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)

image.png

image.png

(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

        image.png

        


image.png

Workflow Demo:

        Into the working directory, execute the clear command (after clean up, this is a new directory)

        New file and writes content:

                image.png

        View status:

                image.png

        Add files to the staging area, view the status:

                image.png

        Submitted to the local repository:

                git commit -m "first commit"

                image.png

        Then, the product manager temporary change requests, change the next:

                image.png

        Just made changes, to be submitted to the staging area, otherwise, there is no local modified records:

                git add test.txt

                image.png

                (然而,还没有进行自测,到这步,拎包走人)

        在commit到本地仓库之前,产品经理pao过来说:修改不需要了。所以,要回滚到上那次:

                image.png

                (暂存区的修改回归到工作区。但工作区还没有弄干净clean)

        通过git checkout命令将工作区的文件弄干净

                在git checkout命令执行之前,先看下test.txt的内容:

                        image.png

                执行完git checkout命令后:

                        image.png

                        image.png(干净的)

                        image.png

        接下来,又修改了代码:

                image.png

        再添加到暂存区,然后提交到本地仓库

                image.png

        接下来,产品经理说:第二次需求其实不要做,需要回滚到第一次

                查看git提交日志:

                        image.png

                回滚到第一次提交:

                        image.png

                        (进行回滚,--hard说明最终仓库和暂存区文件都回滚到第一次提交)

                        现在,又变回了第一次提交后的状态:

                                image.png

        这时候,产品经理很欠抽的说:其实大家做的这么多都不用做的!你们要把本地仓库清理干净:

                image.png

                (本地清空了,但暂存区和本地仓库没有)

                git commit之后才说明清空了:

                        image.png

        


提交到远程github:

        先要创建ssh key:

                image.png

                image.png

                在git-bash运行命令 ssh-keygen.exe -t rsa -C "[email protected]"(自己的git邮箱):

                        image.png

                其实是保存在了git的家目录:

                        image.png

                查看生成的公钥:

                        image.png

                将公钥粘贴到github:

                        image.png

                测试是否是通的:

                        image.png

        添加远程仓库:

                主要用这几个命令:

                        git remote add origin [email protected]:xxoo/xxoo.git

                        git pull origin master --allow-unrelated-histories

                        git push -u origin master

                先在github上创建新的仓库:

                        image.png

                        image.png

                        image.png

                然后在git-bash执行相关操作:

                        先进入工作目录:

                                image.png

                        创建并写入README.md文档:

                                image.png

                        初始化仓库:

                                git init

                                image.png

                        添加到暂存区:

                                git add

                                image.png

                        添加到本地仓库master分支

                                git commit -m "first commit"

                                image.png

                        本地仓库与远程github关联起来:

                                git remote add origin [email protected]:xxoo/websocket_push.git

                                image.png

                        推到github上:

                                image.png

                        查看github,会发现已经提交上来了:

                                image.png

                        改一下,再次提交:

                                image.png

                                (第一次git push -u origin master,接下来就可以git push)

                        查看github,已经更新了:

                                image.png



克隆仓库:

        命令:

                git clone [email protected]:xxoo/xxoo.git

        测试:

                image.png



标签管理:

        命令:

                git tag——>查看所有标签

                git tag name——>创建标签

                git tag -a name -m "commet"——>指定提示信息

                git tag -d name——>删除标签

                git push origin name——>标签发布

        演示:

                image.png

                image.png

                image.png

        查看标签:

                image.png

        

                        

分支管理:

        假设现在有个场景,你准备开发一个新功能,但需要两周时间才能完成,但只写了50%代码,如果立即提交,由于代码没有写完,不完整的代码可能导致项目运行出问题。但如果想把所有的代码写完,再一次提交,就会存在丢失每天进度的风险,有了分支就不用担心这个问题了。你只要创建属于你自己的分支,别人看不到,你只要在自己的分支上工作。而在自己的分支上,怎么提交都行。当你写完之后再合并到原来分支,这样既安全,又不影响工作。

        image.png

        演示:

                image.png

                (ls -a查看,没有看到.git文件,说明没有仓库)

                image.png

                image.png

                创建新的分支(git branch):

                image.png

                查看分支:

                image.png

                (*说明在什么分支上)

                切换到分支:

                image.png

                Based on the current branch, code editor:

                image.png

                The new code merged into the master branch up:

                image.png(To switch to the master branch)

                Merge up to master:

                image.png

                image.png

                Continue to write the code, find the branch feature_x has no use, this time we should be deleted branches of:

                image.png



to sum up:

        image.png

Guess you like

Origin blog.51cto.com/5660061/2400288