Can I merge/sync a sub-folder from one branch to the root of another in git?

喜你入骨 提交于 2019-12-06 08:43:23
VonC

One nice trick would be to declare the branch gh-branch as a submodule in your master branch (also more detailed in "How to add a git repo as a submodule of itself?").

That way, when you are in your master branch, you see a folder gh-branch which represents the gh-branch content.

You could then:

  • version doc only in the gh-branch
  • have a symlink doc in your master branch, linked to gh-branch/doc

That way, you maintain the doc/ content only in one place.

#!/bin/sh

# if there's a docbranch tree and it matches master:doc,
# then get out now, there's nothing to do:

current=`git rev-parse -q --verify docbranch:` \
&& test $current = "`git rev-parse -q --verify master:doc`" \
&& exit 0

# update the docbranch ref to a new commit ...    
git update-ref refs/heads/docbranch $(
        # ... which has master:doc, parented on docbranch if that exists yet
        git commit-tree ${current:+-p docbranch} -m "updating" master:doc
)

You can use that as your post-commit hook and chmod +x it, every time you commit anything, if the master doc directory has changed it will commit it to the head of docbranch.

Since the tree's already committed, the only thing this adds is the (~200 byte) commit object itself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!