简体   繁体   中英

git merge from subtree folder in master to branch root

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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