在Git中,本地分支可以跟踪另一个 - 这有何用处? [英] In Git, local branches can track one another - how is this useful?

查看:414
本文介绍了在Git中,本地分支可以跟踪另一个 - 这有何用处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说在 Git 中,可以让本地分支A 跟踪另一个本地分行B



为什么有人想要这样做?

想到让本地分支跟踪另一个本地分支的事情,(1)Git提供了关于分支在追踪分支前后的更多消息,以及(2)触发钩子。

在创建分支时,一个区域Git显示更多信息。创建一个基本分支如下所示:

  $ git co -b一个master 
切换到一个新分支'A'

在创建跟踪分支时,看起来像:

  $ git co --track -b B master 
分支B设置为跟踪本地分支主机。
转换为新分支'B'

这会在<$ c中添加以下内容$ c $ .git / config :

  [branchB] 
remote =。
merge = refs / heads / master

在分支机构 B ,在分支<$上执行 git status -s -b 在分支 B 时,c $ c> A 显示 ## A ,它显示 ## B ... master [advance 1,behind 1] ,提供了关于分支 B master



您可能想要本地分支跟踪另一个本地分支的另一个区域是触发;特别是 pre-receive 更新邮寄收据 git中的更新后 。例如,您可能会挂钩,以便在持续集成服务器上触发构建,执行一些许可证标头检查,检查空白格式错误等。


I heard that in Git, you can let a local branch A track another local branch B.

Why would someone want to do that?

解决方案

The main things that come to mind for having a local branch track another local branch are (1) more informed messages from Git regarding a branch being ahead/behind of the tracked branch and (2) trigger hooks.

One area Git displays more information is when creating a branch. Creating a basic branch looks like the following:

$ git co -b A master
Switched to a new branch 'A'

While creating a tracking branch looks like:

$ git co --track -b B master
Branch B set up to track local branch master.
Switched to a new branch 'B'

This would add the following in .git/config:

[branch "B"]
    remote = .
    merge = refs/heads/master

After committing some changes on branches A and B, executing git status -s -b on branch A displays ## A while on branch B it displays ## B...master [ahead 1, behind 1], providing some quick information regarding the relationship between branches B and master.

The other area where you might want a local branch track another local branch is to trigger hooks; in particular pre-receive, update, post-receive and post-update during a git push. You might have hooks to, for example, trigger a build on a continuous integration server, do some license header checks, check for white space format errors, etc.

这篇关于在Git中,本地分支可以跟踪另一个 - 这有何用处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆