git从master中的子树文件夹合并到分支根 [英] git merge from subtree folder in master to branch root

查看:937
本文介绍了git从master中的子树文件夹合并到分支根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我的问题是:

是否有一种方法可以从 master 中的文件夹合并到分支中的根



我想要的是: $ b


  1. 分支 master 分支中的文件夹读取树
  2. master下进行一些更改(添加子树文件夹中的文件) 分支

  3. master 中的子树文件夹中的更改(添加的文件)合并到分支 root

我试过这个教程: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging

但结果出乎意料:



我做了:

  $ git init 
$ touch fileInMaster
$ git add -A
$ git commit --all -m'initial commit'
$ git checkout master
$ git remote add rack_remote https://github.com /schacon/rack.git
$ git fetch rack_remote
$ git checkout -b rack_branch rack_remote / master
$ git checkout master
$ git read-tree --prefix = rack / -u rack_branch
$ git add -A
$ git commit --all -m'将文件读取到文件夹后'
$ echo 0> rack / fileInRack
$ git add -A
$ git commit --all -m'将fileInRack文件添加到rack文件夹'
$ git merge --squash -s subtree --no-commit rack_branch

我期望的是:


  • master 分支中的新文件'fileInRack'位于 rack 文件夹中
  • 新文件'fileInRack'在 rack_branch
  • 的根目录下


但是在子树合并后git注意到我:


删除rack / fileInRack

壁球提交 - 不会更新HEAD

自动合并进行顺利;停止之前提交请求


但我需要添加,而不是删除。

那么,我做错了什么?

是否有其他方法可以从 master 中的文件夹合并到root branch

解决方案

而不是

 git merge --squash -s subtree --no-commit rack_branch 

你可以这样做:

$ g $ check $ g $ g $ g $ git merge --squash -s递归-Xsubtree --allow - 无关的历史记录master
git commit -mcommit fileInRack to rack_branch

编辑:我偶然发现这篇文章的原因是我有一个类似的问题,我上面的解决方案不起作用(见这里)。请注意关于 - no-ff 选项的编辑。总是使用这个选项可能是个好主意?


Actually my question is:
Is there a way to merge from folder in master to root in branch?

What i want is:

  1. read-tree from branch to folder in master branch
  2. make some changes (add files in subtree folder) under master branch
  3. merge theese changes (added files) from subtree folder in master to branch root

I've tried this tutorial: https://git-scm.com/book/en/v1/Git-Tools-Subtree-Merging
But results are unexpected:

I did:

    $ git init
    $ touch fileInMaster
    $ git add -A
    $ git commit --all -m 'initial commit'
    $ git checkout master
    $ git remote add rack_remote https://github.com/schacon/rack.git
    $ git fetch rack_remote
    $ git checkout -b rack_branch rack_remote/master
    $ git checkout master
    $ git read-tree --prefix=rack/ -u rack_branch
    $ git add -A
    $ git commit --all -m 'After read-tree to rack folder'
    $ echo 0 > rack/fileInRack
    $ git add -A
    $ git commit --all -m 'Add fileInRack file to rack folder'
    $ git merge --squash -s subtree --no-commit rack_branch

What i'm expect is:

  • New file 'fileInRack' in master branch in rack folder
  • New file 'fileInRack' in root of rack_branch

But after subtree merging git notice me:

Deleting rack/fileInRack
Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested

But i need adding, not deleting.

So, what am i doing wrong?
Is there other way to merge from folder in master to root in branch?

解决方案

Instead of

git merge --squash -s subtree --no-commit rack_branch

you can do

git checkout rack_branch
git merge --squash -s recursive -Xsubtree --allow-unrelated-histories master
git commit -m "commit fileInRack to rack_branch"

EDIT: The reason I stumbled across this post is that I have a similar problem, and my solution above doesn't work (see here). Note the edit about the --no-ff option. It may be a good idea to always use this option?

这篇关于git从master中的子树文件夹合并到分支根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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