首页 > PHP资讯 > PHP培训技术 > 我知道的php培训机构最清晰的git详情,及其git怎么用

我知道的php培训机构最清晰的git详情,及其git怎么用

PHP培训技术

现在很多的php培训机构发布各种的git教程,但是每一家都弄的乱七八道的。最后学完一篇,好像什么都么有学到,发而越弄越乱。近期我发现了一家php培训学校分享的git版本控制器的使用。在这里分享给php的爱好者。

git版本控制器

 

1、什么是版本控制器?

公司流水账(几年)-防止不可预计的危险使数据丢失

  1. 20170101财务.xls
  2. 20170201财务.xls
  3. 20170301财务.xls

使用工具来管理用户的某些文件或者数据,及其实现用户的数据共享,并且记录用户的操作行为。这种工具就叫做版本控制器。

2、版本控制种类?

  1. 集中式的版本管理控制器:cvs(丢弃) svn subversions(任何公司都可以使用)
  2. 分布式的版本管理控制器:git(软件类的代码开发)

3、git和svn的优缺点

  1. 1、svn是集中管理式的,而git是分布式的;svn是以文件的方式管理的,git他是元数据管理(修改的数据组成的日志记录)git速度上比svn快。
  2. 2、svn必须有网络才能操作,git是可以离线操作的。
  3. 3、svn的分支创建切换时太慢,大家基本没有人使用。 git的分支比svn更容易切换和更方便使用
  4. 4、svn有统一的全局版本概念,git没有全局版本概念,通过tag标志来实现的。

4、git的初始化和基本操作

第一使用:自报家门

$ git config --global user.name "用户名"
$ git config --global user.email "邮箱"
c:/用户[documents users]/电脑用户名/.gitconfig

W@thinksite MINGW64 ~

$ git config --global user.name "thinksitelaowang01"

 

W@thinksite MINGW64 ~

$ git config --global user.email "thinksite@126.com"

 

第二步创建本地仓库
1、创建空文件夹 d:/thinksitegit
2、$ git init 在本文件夹中创建仓库 ~代表根目录
使用cd命令进入本目录,pwd查看当前本目录

W@thinksite MINGW64 ~

$ cd d:

 

W@thinksite MINGW64 /d

$ cd thinksitegit

 

W@thinksite MINGW64 /d/thinksitegit

$ pwd

/d/thinksitegit

 

W@thinksite MINGW64 /d/thinksitegit

$ git init

Initialized empty Git repository in D:/thinksitegit/.git/

 

4.1文件的添加和提交

查看git状态: $ git status

  1. 1、在目录下创建一个文件hello.txt,里面输入一行welcome to git
  2. 2、$ git add 文件名 将文件添加/git add 文件名1 文件名2 ..../git add .
  3. 3、$ git commit -m "说明文字" 将文件提交

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

nothing to commit (create/copy files and use "git add" to track)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

Untracked files:

  (use "git add <file>..." to include in what will be committed)

 

        hello.txt

 

nothing added to commit but untracked files present (use "git add" to track)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

 

        new file:   hello.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "add file hello.txt"

[master (root-commit) a630654] add file hello.txt

 1 file changed, 1 insertion(+)

 create mode 100644 hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

   

   W@thinksite MINGW64 /d/thinksitegit (master)

添加和提交多个文件步骤:

 

$ git status

On branch master

Untracked files:

  (use "git add <file>..." to include in what will be committed)

 

        hello1.txt

        hello2.txt

 

nothing added to commit but untracked files present (use "git add" to track)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello1.txt hello2.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

 

        new file:   hello1.txt

        new file:   hello2.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "add more hello1.txt hello2.txt"

[master 2afbe02] add more hello1.txt hello2.txt

 2 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 hello1.txt

 create mode 100644 hello2.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

 

4.2文件的修改和提交

1、先修改文件

2、使用git status进行查看状态

3、查看修改内容git diff

4git add 文件名  添加

5git commit -m “说明文字”

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git diff

diff --git a/hello.txt b/hello.txt

index 7618940..007c377 100644

--- a/hello.txt

+++ b/hello.txt

@@ -1 +1,2 @@

-welcome to git

\ No newline at end of file

+welcome to git

+this is modify hello.txt

\ No newline at end of file

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

 

        modified:   hello.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "modify hello.txt"

[master c181616] modify hello.txt

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

 

4.3文件的删除和提交

Rm 文件名    删除工作区中的文件

Git rm 文件名  删除的暂存区中的文件和工作区中文件

Git commit -m 说明  删除本地版本库中的文件

 

 

 

 

 

 

  工作区             仓库                                        中央仓库

              Add                                     推送(push)

 

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ rm hello1.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git rm hello1.txt

rm 'hello1.txt'

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "delete hello1.txt"

[master d7d6c09] delete hello1.txt

 1 file changed, 0 insertions(+), 0 deletions(-)

 delete mode 100644 hello1.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

4.4查看更新日志

Git log 查看更新的详细日志信息

 

commit d7d6c09359a4df4457962982a09ba713f4016211 (HEAD -> master)  -> 快照ID  HEAD -> master当前分支

Author: thinksitelaowang01 <thinksite@126.com>    ---提交者

Date:   Wed Dec 27 11:03:01 2017 +0800     ----提交时间

Delete1 hello1.txt                         --------->本次提交的说明文字

   注意:如果没有退出显示的结果就使用:q退出

 

git log --pretty=oneline  查看简易git更新日志

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log --pretty=oneline

d7d6c09359a4df4457962982a09ba713f4016211 (HEAD -> master) delete hello1.txt

c18161641718a9f0c81c9b87aeea90949513b25b modify hello.txt

2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf add more hello1.txt hello2.txt

a630654e622f39cb6175d3b4166f69baccaac977 add file hello.txt

 

4.5回到历史快照中

git reset --hard HEAD^ 或者HEAD~100 或者快照id  回到上一个版本

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git reset --hard HEAD^^

HEAD is now at 2afbe02 add more hello1.txt hello2.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log

commit 2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf (HEAD -> master)

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:38:53 2017 +0800

 

    add more hello1.txt hello2.txt

 

commit a630654e622f39cb6175d3b4166f69baccaac977

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:20:44 2017 +0800

 

add file hello.txt

4.5回到现在快照中

Git reflog   查看用所有指令操作

Git reset --hard 快照id  回到某个快照

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log

commit 2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf (HEAD -> master)

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:38:53 2017 +0800

 

    add more hello1.txt hello2.txt

 

commit a630654e622f39cb6175d3b4166f69baccaac977

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:20:44 2017 +0800

 

    add file hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ cat hello.txt

welcome to git

W@thinksite MINGW64 /d/thinksitegit (master)

$ git reflog

2afbe02 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^^

d7d6c09 HEAD@{1}: commit: delete hello1.txt

c181616 HEAD@{2}: reset: moving to c18161641718a9f0c81c9b87aeea90949513b25b

b246ad0 HEAD@{3}: checkout: moving from master to master

b246ad0 HEAD@{4}: commit: delete hello1.txt

9f5f3a3 HEAD@{5}: commit: delete hello1.txt

c181616 HEAD@{6}: commit: modify hello.txt

2afbe02 (HEAD -> master) HEAD@{7}: commit: add more hello1.txt hello2.txt

a630654 HEAD@{8}: commit (initial): add file hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git reset --har d7d6c09

HEAD is now at d7d6c09 delete hello1.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log

commit d7d6c09359a4df4457962982a09ba713f4016211 (HEAD -> master)

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 11:03:01 2017 +0800

 

    delete hello1.txt

 

commit c18161641718a9f0c81c9b87aeea90949513b25b

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:46:10 2017 +0800

 

    modify hello.txt

 

commit 2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:38:53 2017 +0800

 

    add more hello1.txt hello2.txt

 

commit a630654e622f39cb6175d3b4166f69baccaac977

Author: thinksitelaowang01 <thinksite@126.com>

Date:   Wed Dec 27 10:20:44 2017 +0800

 

add file hello.txt

4.6撤销修改:

    

 

 

   4.6.1、撤销工作区的修改:

    Git checkout -- 文件名   就是将文件还原到原来和版本库中的相同

          W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git diff

diff --git a/hello.txt b/hello.txt

index 007c377..b81f15c 100644

--- a/hello.txt

+++ b/hello.txt

@@ -1,2 +1,3 @@

 welcome to git

-this is modify hello.txt

\ No newline at end of file

+this is modify hello.txt

+fuck Boss

\ No newline at end of file

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout -- hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ cat hello.txt

welcome to git

this is modify hello.txt

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

   4.6.1、撤销暂存区的修改:

         Git reset HEAD 文件名  撤销暂存区到工作区

         Git checkout -- 文件名    撤销工作区的修改

          

 W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

 

        modified:   hello.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git reset HEAD hello.txt

Unstaged changes after reset:

M       hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout -- hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

  4.6.1、撤销仓库中的修改:  直接仓库回退到上一个仓库快照

          Git reset --hard 快照id/HEAD^/HEAD-1

          

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "Fuck Boss modify"

[master aa9678a] Fuck Boss modify

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log --pretty=oneline

aa9678a51b904fb865188e873665f83ac26cea22 (HEAD -> master) Fuck Boss modify

d7d6c09359a4df4457962982a09ba713f4016211 delete hello1.txt

c18161641718a9f0c81c9b87aeea90949513b25b modify hello.txt

2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf add more hello1.txt hello2.txt

a630654e622f39cb6175d3b4166f69baccaac977 add file hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git reset --hard d7d6c09359a4df4457962982a09ba713f4016211

HEAD is now at d7d6c09 delete hello1.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ cat hello.txt

welcome to git

this is modify hello.txt

5、git的分支操作:

               

                                  用户1

5.1、分支的创建

     Git checkout -b 分支名  创建和切换一起执行

     Git branch 分支名

5.2、分支切换

     Git checkout 分支名

5.3、分支合并

     git merge 分支1    将分支1合并到当前分支上

 

    

 

5.4、快照分支合并步骤:

         1、git checkout -b dev

         2、添加 hello5.txt文件

         3、git add hello5.txt

         4、git commit -m 修改注释

          5git checkout master 切回到主分支

          6git merge dev

          7git branch -d dev   删除dev分支

          8git branch -v 查看分支情况  

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -d dev

Deleted branch dev (was 67b4e2c).

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -d test

Deleted branch test (was 67b4e2c).

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -d rm

Deleted branch rm (was 67b4e2c).

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch

* master

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout -b dev

Switched to a new branch 'dev'

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git add hello3.txt

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git commit -m "add hello3.txt"

[dev ded6489] add hello3.txt

 1 file changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 hello3.txt

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git checkout master

Switched to branch 'master'

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git merge dev

Updating 67b4e2c..ded6489

Fast-forward

 hello3.txt | 0

 1 file changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 hello3.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -v

  dev    ded6489 add hello3.txt

* master ded6489 add hello3.txt

5.5、分支合并冲突解决步骤:

                1、先创建dev分支,在dev 分支上修改hello.txt文件内容

                2git add hello.txt

                3git commit -m change boss to compnay

                4git checkout master

                5、修改hello.txt内容

                6git add hello.txt

                7git commit -m change company to laowang

                8git merge --no-ff -m "提交描述" dev        禁用快速合并

            9、解决冲突

            10、git add-> git commit;

            11、git log --graph --pretty=oneline --abbrev-commit  合并情况

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout -b dev

Switched to a new branch 'dev'

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git commit -m "change line fuck boss"

[dev 21ab4bc] change line fuck boss

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git status

On branch dev

nothing to commit, working tree clean

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git checkout master

Switched to branch 'master'

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "change line funck company"

[master 825d23d] change line funck company

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git merge --no-ff -m "merge ct" dev

Auto-merging hello.txt

CONFLICT (content): Merge conflict in hello.txt

Automatic merge failed; fix conflicts and then commit the result.

 

W@thinksite MINGW64 /d/thinksitegit (master|MERGING)

$ cat hello.txt

welcome to git

this is modify hello.txt

this is dev workspace

<<<<<<< HEAD

fuck company

=======

fuck boss

>>>>>>> dev

 

W@thinksite MINGW64 /d/thinksitegit (master|MERGING)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master|MERGING)

$ git commit -m "merge ok"

[master 47f7907] merge ok

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git log --graph --pretty=oneline --abbrev-commit

*   47f7907 (HEAD -> master) merge ok

|\

| * 21ab4bc (dev) change line fuck boss

* | 825d23d change line funck company

|/

* ded6489 add hello3.txt

* 67b4e2c dev add hello.txt

* d7d6c09 delete hello1.txt

* c181616 modify hello.txt

* 2afbe02 add more hello1.txt hello2.txt

* a630654 add file hello.txt

5.5、解决master分支临时bug错误步骤:  暂时存储我当前的工作环境

     Bug不能在master改,会影响整个项目执行

     Bug也不能在dev分支上改,因为dev功能分支还没有开发完毕

     所以需要新建分支和保存当前dev的开发工作环境

              master

 

             dev

 

                                                          Bug分支

           步骤:

               1dev分支中暂存当前工作环境

                  git stash

               2、切换到bug分支中

                  Git checkout -b bug1.0

               3、改完bug

               4、将bug git add添加

               5、将bug gitcommit 提交

               6git checkout master   切换到master分支

               7git merge --no-ff -m "bugok" bug1.0    合并到master分支上

               8、删除bug分支

               9、切回dev分支

               10、还原dev工作环境

         git stash list 查看工作现场
    git stash pop(git stash apply(还原工作环境)+git stash drop(删除暂存环境)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout dev

Switched to branch 'dev'

$ git status

On branch dev

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

Dropped refs/stash@{0} (4dfa0b34fa55eb50a2fb6c97c13ed31127236e6b)

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git stash

Saved working directory and index state WIP on dev: 21ab4bc change line fuck boss

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git checkout -b bug1.0

Switched to a new branch 'bug1.0'

 

W@thinksite MINGW64 /d/thinksitegit (bug1.0)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (bug1.0)

$ git commit -m "bug1.0 ok"

[bug1.0 dba579d] bug1.0 ok

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (bug1.0)

$ git status

On branch bug1.0

nothing to commit, working tree clean

 

W@thinksite MINGW64 /d/thinksitegit (bug1.0)

$ git checkout master

Switched to branch 'master'

 

W@thinksite MINGW64 /d/thinksitegit (master) 有冲突走下面两步,没有冲突就不走)

$ git merge --no-ff -m "bugok" bug1.0

Auto-merging hello.txt

CONFLICT (content): Merge conflict in hello.txt

Automatic merge failed; fix conflicts and then commit the result.

 

 

 

 

 

 

 

W@thinksite MINGW64 /d/thinksitegit (master)  (没有冲突直接这个)

$ git branch -d bug1.0

Deleted branch bug1.0 (was dba579d).

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git stash list

stash@{0}: WIP on dev: 21ab4bc change line fuck boss

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout dev

Switched to branch 'dev'

 

W@thinksite MINGW64 /d/thinksitegit (dev)

$ git stash pop

On branch dev

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git checkout -- <file>..." to discard changes in working directory)

 

        modified:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

Dropped refs/stash@{0} (4dfa0b34fa55eb50a2fb6c97c13ed31127236e6b)

5.6、临时增加的项目功能,可能后期都不需要的。

     强制删除分支:

     Git branch -D 分支名

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git checkout -b model110

Switched to a new branch 'model110'

 

W@thinksite MINGW64 /d/thinksitegit (model110)

$ git status

On branch model110

Untracked files:

  (use "git add <file>..." to include in what will be committed)

 

        hello4.txt

 

nothing added to commit but untracked files present (use "git add" to track)

 

W@thinksite MINGW64 /d/thinksitegit (model110)

$ git add hello4.txt

 

W@thinksite MINGW64 /d/thinksitegit (model110)

$ git commit hello4.txt

Aborting commit due to empty commit message.

 

W@thinksite MINGW64 /d/thinksitegit (model110)

$ git commit -m "hello4.txt"

[model110 b8b036e] hello4.txt

 1 file changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 hello4.txt

 

W@thinksite MINGW64 /d/thinksitegit (model110)

$ git checkout master

Switched to branch 'master'

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -d model110

error: The branch 'model110' is not fully merged.

If you are sure you want to delete it, run 'git branch -D model110'.

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch -D model110

Deleted branch model110 (was b8b036e).

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git branch

  dev

* master

      5.7、项目实际开发分支情况

         1、master主分支上开发:冲突次数太多,且对于网站安全性不好

        master     

         2、开发分支开发:

         Master                                     推送正常运行网站

         Dev分支                                      推送测试站

         用户1

         用户2类似用户1

6、Git远程仓库操作:

1、第三方托管仓库:github官网    oschina-码云

2、自建git服务器:项目安全性较高的时候。

 

注册码云账户:https://gitee.com/

github账户:https://github.com

 

6.1、使用步骤:

1、生成ssh公匙:

       ssh-keygen -t rsa -C "我的SSH密钥"

          验证公钥是否认证成功

         

        查看公钥: cat ~/.ssh/id_rsa.pub 复制到码云的ssh认证中

  

 

认证成功:ssh -T git@git.oschina.net

 

 W@thinksite MINGW64 ~

$ cat ~/.ssh/id_rsa.pub

cat: /c/Users/W/.ssh/id_rsa.pub: No such file or directory

 

W@thinksite MINGW64 ~

$ cat ~/.ssh/id_rsa.pub   找不到文件复制文件到该目录下或者将git用户名和密码配置成码云的

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPdvkwPHTnGWVVECw2amE/LajuVQwrMtjmBeUtbEfSrkLGcj9BsNlzVB4Tqzq28hupquSIqo/imZh5UCkRdWfapdh4eaNwR8XeNofyD6ozWz94UepC6Yt+KPSrJGq3s4ePQKlmLXkvQXX4l8aNsFk4Smn+LH+6HZempjt/AZcJEqjxcO1j4zE5yaEScXePPeUMiKFtkbrxP18mp4crRm5qudOvmTYX6Rx5RoWWvOJYCHELwXPTBdboEAdJf7WaJ8Fz7AlqBI8nEfz6Iv2TxnQjSDf3DyVNUd8BGoSvIf4D+t9Eze1WO6WUW0uWPBDq/YTXfjlnwcQu3qFzXNu2RG0f 406923210@qq.com

 

W@thinksite MINGW64 ~

$ ssh -T git@git.oschina.net

Welcome to Gitee.com, thinksite002!

6.2、与远程库建立连接:

     git remote add origin <你的项目地址> //:项目地址形式为:https://gitee.com/xxx/xxx.git或者 git@gitee.com:xxx/xxx.git

     例子:git remote add origin https://gitee.com/thinksite002/thinksitegit1.git

         Git remote add origin git@gitee.com:thinksite002/thinksitegit1.git

 

6.3、push:推送数据:将本地的master分支推送到远程的仓库的master分支上

     先用本地仓库 -> 远程仓库

     git push -u origin master -f

     Git pull origin master

W@thinksite MINGW64 /e/test11

$ git init

Initialized empty Git repository in E:/test11/.git/

 

W@thinksite MINGW64 /e/test11 (master)

$ git remote add origin1 git@gitee.com:thinksite002/thinksitegit1.git

 

W@thinksite MINGW64 /e/test11 (master)

$ git push -u origin master -f

Counting objects: 3, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 262 bytes | 131.00 KiB/s, done.

Total 3 (delta 0), reused 0 (delta 0)

To gitee.com:thinksite002/thinksitegit1.git

   ae34ae0..4f28bce  master -> master

Branch 'master' set up to track remote branch 'master' from 'origin'.

 

W@thinksite MINGW64 /e/test11 (master)

$ git pull origin1 master

fatal: No remote repository specified.  Please, specify either a URL or a

remote name from which new revisions should be fetched.

 

W@thinksite MINGW64 /e/test11 (master)

$ git pull origin1 master

remote: Counting objects: 6, done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 6 (delta 0), reused 0 (delta 0)

Unpacking objects: 100% (6/6), done.

From gitee.com:thinksite002/thinksitegit1

 * branch            master     -> FETCH_HEAD

 * [new branch]      master     -> origin1/master

 

6.4、克隆仓库和常见的基本操作

     项目一般一开始时,先创建远程的仓库,然后第一次使用克隆将远程仓库下载到本地

 

        Git clone ssh地址/是https地址

 

W@thinksite MINGW64 ~

$ cd g:

 

W@thinksite MINGW64 /g

$ cd wwwroot

 

W@thinksite MINGW64 /g/wwwroot

$ git clone git@gitee.com:thinksite002/thinksitemiddle.git

Cloning into 'thinksitemiddle'...

remote: Counting objects: 3, done.

remote: Total 3 (delta 0), reused 0 (delta 0)

Receiving objects: 100% (3/3), done.

 

W@thinksite MINGW64 /g/wwwroot

$ cd thinksitemiddle

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (master)

$

   6.4.1、remote分支管理:

          Git remote   查看有多少的remote分支

          Git remote -v 查看详细的remote情况

          Git remote rm 分支名    删除掉某个remote

          如果多人协助开发时冲突解决:

               会出现同一个文件被多人修改推送,先git pull将远程代码拉取下来,然后解决冲突,然后add -》commit -》 push提交

          注意:如果项目开发过程中出现了ssh公钥的变化,请重新建立本地仓库master和远程仓库master的链接。

          练习:

              1、cd d:

              2、克隆thinksitemiddle的远程库(下载代码,创建了本地master到远程origin/master链接)

                  Git clone git@gitee.com:thinksite002/thinksitemiddle.git

              3、进入thinksitemiddle文件夹-thinksitemiddle (master)

          4、每个人拿自己的名字,创建xxx.php文件,写入一句话

          5、添加->提交->推送

             Git add  xxx.php

             Git commit -m xxx add newfile xxx.php

             Git push origin master    (some to refers)

             Git pull  -> :q退出

             Git push origin master

   6.4.2、远程分支操作

       创建分支时,确定是最新的版本

       如果不是最新版本    

git fetch(不合并)/git pull(合并) 下载一下最新版本

       git checkout -b dev origin/dev 创建远程 的dev分支

 

        W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (master)

$ git fetch

remote: Counting objects: 55, done.

remote: Compressing objects: 100% (49/49), done.

remote: Total 55 (delta 20), reused 0 (delta 0)

Unpacking objects: 100% (55/55), done.

From gitee.com:thinksite002/thinksitemiddle

 * [new branch]      dev        -> origin/dev

   e1288e6..3ad9c1c  master     -> origin/master

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (master)

$ git checkout -b dev origin/dev

fatal: A branch named 'dev' already exists.

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (master)

$ git branch -d dev

Deleted branch dev (was e1288e6).

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (master)

$ git checkout -b dev origin/dev

Switched to a new branch 'dev'

Branch 'dev' set up to track remote branch 'dev' from 'origin'.

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (dev)

$ git add 111.txt

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (dev)

$ git commit -m "dev 111.txt"

[dev 2354eb0] dev 111.txt

 1 file changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 111.txt

 

W@thinksite MINGW64 /g/wwwroot/thinksitemiddle (dev)

$ git push origin dev

Counting objects: 3, done.

Delta compression using up to 4 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 264 bytes | 132.00 KiB/s, done.

Total 3 (delta 1), reused 0 (delta 0)

To gitee.com:thinksite002/thinksitemiddle.git

   3ad9c1c..2354eb0  dev -> dev

 


    git pull 最新提交拿到本地不成功就no tracking information 
    git branch --set-upstream dev origin/dev 让本地连接和远程dev   

  1. 忽略文件: 不想推送和提交的文件

   .gitignore

         *.asp

         Common.php

              

综上所述,我们知道php培训结构有很多,但是我认为篇文章是比较代表性的,希望这篇php培训学校讲解的git的应用能对大家有帮助,谢谢大家支持!

          

 

     

      

 

 

 

本文由欣才IT学院整理发布,未经许可,禁止转载。