我B从A具有跟踪选项的分支创建了一个新的git分支。
现在,当A分支通过很少的提交进行更新时,我也希望将提交也移至该提交B,因此我可以对其进行跟踪,并且以后不必再面对较大的更改。
我应该如何处理?它是在git中自动完成的吗?
Answers:
这不是自动进行的。您必须手动将您的更改从A合并到B,这非常简单。只需切换到分支B并执行
git merge A
这将自动将您的更改从A合并到B。只要您没有任何冲突,A中的所有更改都将被标记为B中的合并。一种常见的最佳做法是进行每日合并,但这取决于有关使用您的分支机构的用户/提交数的信息。
git merge origin A 应该进一步增强这一功能
git branch A带有一些随机选项的分支。因此,如果我只是进行git pull,则git会抱怨You asked me to pull without telling me which branch you want to merge with...
pull仅当您要从远程获取数据时才需要。如果您A刚上过并且刚刚做过git checkout -b B,则可以简单地merge(在上时B,键入git merge A)。
这是我如何使其工作的方式。
简洁版本:
git checkout feature/mychildbranch
git branch
git checkout feature/myparentbranch
git pull
git branch
git checkout feature/mychildbranch
git branch
git merge feature/myparentbranch
较长的版本(解释)我将使用/ *作为注释* /
/* first, make sure you at least have the child branch */
git checkout feature/mychildbranch
/* ok, just show the branches. make sure at least feature/mychildbranch exists note the "*" below says "this is the branch i am on" */
git branch
* feature/mychildbranch
feature/myparentbranch
/* now checkout the parent branch...note the "switched" happens automatically with the checkout */
git checkout feature/myparentbranch
Switched to branch 'feature/myparentbranch'
Your branch is up to date with 'origin/feature/myparentbranch'.
/* not pull, the pull will occur on the branch you are currently on, which should be feature/myparentbranch at this point */
git pull
remote: Enumerating objects: 69, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 22 (delta 17), reused 0 (delta 0)
Unpacking objects: 100% (22/22), done.
From https://mygit.hub.com
96ae0e9..6eb0a03 feature/myparentbranch -> origin/feature/myparentbranch
* [new branch] feature/blah blah blah (specific to my stuff only)
xb99638..x86db6f master -> origin/master
Updating x6ae0e9..xeb0a03
Fast-forward
.../somefileone.txt | 30 ++++++++++++--------
.../somefiletwo.txt | 7 +++--
.../somefilethree.txt | 6 ++--
X files changed, Y insertions(+), Z deletions(-)
create mode 100644 somenewfileone.txt
/* do a git branch just to show that you're on feature/myparentbranch */
git branch
feature/mychildbranch
* feature/myparentbranch
/* ok, now (above) you have the latest-greatest feature/myparent, lets do a checkout on the child to switch to the child */
git checkout feature/mychildbranch
Switched to branch 'feature/mychildbranch'
Your branch is up to date with 'origin/feature/mychildbranch'.
/* another sanity check, show you're on feature/mychildbranch */
git branch
* feature/mychildbranch
feature/myparentbranch
/* finally, the magic. do a merge from feature/myparentbranch (which you know is local and up to date because of the voodoo above */
git merge feature/myparentbranch
Merge made by the 'recursive' strategy.
.../somefileone.txt | 30 ++++++++++++--------
.../somefiletwo.txt | 7 +++--
.../somefilethree.txt | 6 ++--
X files changed, Y insertions(+), Z deletions(-)
create mode 100644 somenewfileone.txt
如果没有冲突,那么您应该在想要的地方。如果存在冲突,那就是全新的SOF问题/答案恕我直言。
git merge origin A这是否应该使我免于回到父分支,在那里拉,然后又回到孩子去执行其他事情
与父母合并:
运行两个命令非常重要:
仅供参考:现在,在您的本地历史记录/日志中,您将看到提交列表,但这将提交与本地而不是远程的父分支相关联的更改。
要在github之类的遥控器上查看所有更改,只需执行
在子公司B,我们可以做
git merge origin A
这样可以使其与父母的出身保持同步。