Git command - branch

Related command in Git branch operations:

  1. Branch git $ <new new-Branch>        # create a new branch
  2. Git Checkout $ <branbch_name>          # switch to the specified branch
  3. Checkout -b git $ <branbch_name>   # Create and switch to the new branch
  4. Merge git $  <branch_name>             # specified branch into the current branch
  5. Git Branch -d $ <branch_name>     # delete the specified branch

 

1. Create a branch

When you create a Git branch just created a new pointer to a possible move for you. For example, create a testing branch, you need to use git branch command:

  $ git branch testing

This creates a pointer on where to submit the current object:

 

2. handover branch 

To switch to an existing branch, you need to use git checkout command. E.g:

$ git checkout testing

Such HEAD points to the testing branch.

 

If you want to create a branch at the same time to switch to that branch, you run with -b arguments git checkout command. E.g:

$ git checkout -b branch_name

It is shorthand for the following two commands:

$ git branch branch_name

$ git checkout branch_name

 

3. 分支合并

通过 git merge 命令可以实现分支合并的操作,例如:

 

在这种情况下,你的开发历史从一个更早的地方开始分叉开来(diverged)。 因为,master 分支所在提交并不是 iss53 分支所在提交的直接祖先,Git 不得不做一些额外的工作。 出现这种情况的时候,Git 会使用两个分支的末端所指的快照(C4 和 C5)以及这两个分支的工作祖先(C2),做一个简单的三方合并。

 

和之前将分支指针向前推进所不同的是,Git 将此次三方合并的结果做了一个新的快照并且自动创建一个新的提交指向它。 这个被称作一次合并提交,它的特别之处在于他有不止一个父提交

 

Guess you like

Origin www.cnblogs.com/shichangxing/p/11489271.html