简体   繁体   English

Git 在分支的分支上拉取

[英]Git Pulling and Fetching on a branch of a branch

Git newbie here, using Visual Studio rather than command line to issue commands. Git 新手在这里,使用Visual Studio而不是命令行来发出命令。 My understanding of a good branching strategy is we have a "main" in the repository.我对良好分支策略的理解是我们在存储库中有一个“主”。 We then have a "dev" branch from main which all developers work from.然后,我们有一个来自 main 的“dev”分支,所有开发人员都在该分支上工作。 To implement changes we branch from "dev" branch then check back in to "dev" when work is complete via pull requests.为了实现更改,我们从“dev”分支分支,然后在工作完成后通过拉取请求签入“dev”。 Once "dev" work is completed after several weeks, "dev" is merged into "main".一旦“dev”工作在几周后完成,“dev”就会合并到“main”中。

在此处输入图像描述

What I'm struggling to satisfy myself is that if i'm working on my local branch (from "dev"), and I fetch or pull in Visual Studio to bring it up to date with other developers changes, i expect it to pull from "dev" as that is what i branched from originally.我正在努力满足自己的是,如果我在本地分支上工作(来自“dev”),并且我获取或拉入 Visual Studio 以使其与其他开发人员的更改保持同步,我希望它能够拉动来自“dev”,因为那是我最初的分支。 There is nothing to show in Visual Studio Synchronisation that is what it is doing. Visual Studio 同步中没有什么可以显示它正在做的事情。

It just says " Pulling changes for the local branch " and this is all it shows:它只是说“为本地分支拉取更改”,这就是它所显示的全部内容:

在此处输入图像描述

Can anyone clarify in this scenario that it will pull/fetch from originating branch ie "dev" and not the "main"?任何人都可以在这种情况下澄清它将从原始分支(即“dev”而不是“main”)中提取/获取吗? I've looked all over but cannot find anything that convinces me, i suspect it will be clearer using some command line tool.我已经看了一遍,但找不到任何能说服我的东西,我怀疑使用一些命令行工具会更清楚。

git pull (or the equivalent GUI command) updates the current branch to the latest version on the server. git pull (或等效的 GUI 命令)将当前分支更新到服务器上的最新版本。 Therefore, this usually only does something when you are on develop or master, or in the rare case when multiple developers are working on a feature branch.因此,这通常只在您处于开发或主控状态时才会起作用,或者在极少数情况下,当多个开发人员在一个特性分支上工作时。

git fetch pulls all changes to all branches from the server, but does not update your working copy. git fetch将所有更改从服务器拉到所有分支,但不会更新您的工作副本。 Typically, you'll look at the history after a git fetch and manually update your working copy, either by merging develop to your working branch or (more commonly) by rebasing your working copy on the latest dev branch.通常,您将查看 git 获取后的历史记录并手动更新您的工作副本,方法是将开发合并到您的工作分支,或者(更常见的是)将您的工作副本重新定位到最新的开发分支。 In visual studio, you can do the merge by right-clicking on a branch (other than the current) and executing the "merge branch to current branch" command.在 Visual Studio 中,您可以通过右键单击分支(当前分支除外)并执行“合并分支到当前分支”命令来进行合并。 To rebase your branch on another, choose "Rebase current branch on"要将您的分支重新设置为另一个分支,请选择“重新设置当前分支”

Here's how the menu looks like (sorry, only got a german screenshot, but you should get the point)这是菜单的样子(抱歉,只有德语截图,但你应该明白这一点)

分支操作的上下文菜单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM