[英]How to pull a branch which is being created from another branch in GIT
I have a codebase in a branch developmentV2
.我在分支
developmentV2
有一个代码库。 From developmentV2
I have created a branch rahulV2
as below.从
developmentV2
我创建了一个分支rahulV2
如下。
git checkout -b rahulV2 developmentV2
git push origin/rahulV2
I have made some changes in rahulV2
branch.Before pushing it to rahulV2
branch I want to have updated code from developmentV2
if anyone has pushed some code to developmentV2
.我已经取得了一些变化
rahulV2
branch.Before它推到rahulV2
分支我想从更新的代码developmentV2
如果有人推一些代码developmentV2
。
So I stash my changes in rahulV2
.所以我把我的更改藏在
rahulV2
。
git stash
if I will use如果我会使用
git pull
it will get pulled from origin/rahulV2
.它将从
origin/rahulV2
。
I want to pull developementV2
code so that rahulV2
will be updated and after pushing the code I can merge my rahulV2
changes to developmentV2
branch.我想拉
developementV2
代码,以便rahulV2
将被更新,推动我可以合并我的代码后rahulV2
变为developmentV2
分支。
Please help me out with this.这个你能帮我吗。
There are two accepted ways of updating your branch with your parent branch (or any other branch actually).有两种可接受的方式可以使用您的父分支(或实际上任何其他分支)更新您的分支。 This are: Merge and Rebase .
它们是: Merge和Rebase 。
Rebase : Rebase means that you change the history of your commits. Rebase :Rebase 意味着您更改提交的历史记录。 In Git every commit has a parent commit.
在 Git 中,每个提交都有一个父提交。 What rebase does is change the parent commit of the first commit of your branch (when your branch started) to the last commit of the branch you rebase on.
rebase 所做的是将您的分支的第一次提交(当您的分支启动时)的父提交更改为您所基于的分支的最后一次提交。 This changes the history of your commits, but makes it look tidier.
这会更改您提交的历史记录,但使其看起来更整洁。 The way to do it is:
这样做的方法是:
git checkout developementV2
git pull # to make sure you rebase onto the updated version
git checkout rahulV2
git rebase developementV2
Merge : With this method you don't change the history of your commits.合并:使用这种方法,您不会更改提交的历史记录。 All this does is create a new commit with both the changes in your branch and your base branch (in this case
developmentV2
and rahul2
).所有这些都是创建一个新提交,其中包含您的分支和基础分支(在本例中为
developmentV2
和rahul2
)中的rahul2
。 Merge is less dangerous than rebase, for it can generate conflicts only one time, while rebase can give you conflicts for every commit between your old and your new origin commit.合并比 rebase 危险性小,因为它只能产生一次冲突,而 rebase 可以为您的旧源提交和新源提交之间的每次提交带来冲突。 The way to merge is:
合并方式为:
git checkout developementV2
git pull
git checkout rahulV2
git merge developementV2
In both cases you might get conflicts.在这两种情况下,您都可能会遇到冲突。 This means you have to go into the code and decide which version you'll want to take.
这意味着您必须进入代码并决定要采用哪个版本。
This is quite typical workflow.这是非常典型的工作流程。
git checkout developementV2
git pull
git checkout rahulV2
git merge developementV2
But just in case this is a recurrent task, maybe consider an alias?但以防万一这是一个经常性的任务,也许考虑一个别名?
git config --global alias.upd '!f() { git fetch && git checkout developementV2 && git merge --ff-only origin/developementV2 && git checkout -; }; f'
then each time you need to get your rahulV2
branch up to date with the state of developementV2
, do然后每次你需要得到你的
rahulV2
分公司了解最新的状态developementV2
,做
# update your developementV2 branch from remote
git upd
# merge changes in
git merge developementV2
origin/rahulV2
is a remote tracking branch, and gets updated with changes from the remote repository every time you do a git fetch. origin/rahulV2
是一个远程跟踪分支,每次执行 git fetch 时都会根据远程存储库中的更改进行更新。 On the other hand, rahulV2
is your local version of this branch.另一方面,
rahulV2
是这个分支的本地版本。 rahulV2
may be out of sync with origin/rahulV2
which in turn may be out of sync with what is actually on the remote repository. rahulV2
可能与origin/rahulV2
不同步,而origin/rahulV2
又可能与远程存储库上的实际内容不同步。
Hence the difference in doing a merge will depend on the differences in the various incarnates of rahulV2
.因此,进行合并的差异将取决于
rahulV2
的各种化身的rahulV2
。 If you want to merge the very latest rahulV2
into your developmentV2
then you should do the following:如果您想将最新的
rahulV2
合并到您的developmentV2
那么您应该执行以下操作:
git checkout rahulV2 # update remote tracking rahulV2
# git pull origin rahulV2
git checkout developmentV2 # switch to developmentV2
git merge rahulV2 # merge
I tried我试过
git checkout developmentV2 git checkout developmentV2
git pull拉
Here there were new 15 commits which has been pulled.这里有 15 个新提交已被拉取。
Then I tried然后我试过了
git checkout rahulV2 git 结帐 rahulV2
Here it is showing Your branch is ahead of 'origin/rahulV2' by 15 commits.此处显示您的分支领先于 'origin/rahulV2' 15 次提交。
I think the fact that the branch is being created by another will not affect the pull effect.我认为分支由另一个创建的事实不会影响拉动效果。 What you need is just pull it and get the changes you want, anyway, by the time you get the changes it will not matter if they came from a branch that comes from another.
您所需要的只是拉取它并获得您想要的更改,无论如何,当您获得更改时,它们是否来自来自另一个分支的分支都无关紧要。
Hope this was helpful希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.