git在项目中的实际运用

项目中只运用git版本管理的情况下:

1.创建分支命令:

git branch (branchname)

  切换分支命令:

git checkout (branchname)

         当你切换分支的时候,Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录。

 合并分支命令:

    git merge 

2.列出分支

列出分支基本命令:

git branch

没有参数时,git branch 会列出你在本地的分支。

$ git branch
* master

当你执行 git init 的时候,缺省情况下 Git 就会为你创建"master"分支。

如果我们要手动创建一个分支。执行 git branch (branchname) 即可。

$ git branch testing
$ git branch
* master
  testing

3.删除分支

删除分支命令:

git branch -d (branchname)

例如我们要删除"testing"分支:

$ git branch
* master
  testing
$ git branch -d testing
Deleted branch testing (was 85fc7e7). $ git branch * master

4.分支合并

一旦某分支有了独立内容,你终究会希望将它合并回到你的主分支。 你可以使用以下命令将任何分支合并到当前分支中去:

git merge
$ git branch
* master
  newtest
$ ls
README        test.txt    test2.txt $ git merge newtest Updating 2e082b7..556f0a0 Fast-forward test2.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test2.txt $ ls README        test.txt

以上实例中我们将 newtest 分支合并到主分支去,test2.txt 文件被删除。

5.合并冲突

合并并不仅仅是简单的文件添加、移除的操作,Git 也会合并修改。

$ git branch
* master
$ cat test.txt
runoob.com
 
 


猜你喜欢

转载自www.cnblogs.com/fron-tend/p/10272768.html
今日推荐