I want to have a /doc folder in master and easily merge/sync it to the root of a gh-pages branch. What is the easiest way to do this?
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 thegh-branch
- have a symlink
doc
in your master branch, linked togh-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.
来源:https://stackoverflow.com/questions/23962446/can-i-merge-sync-a-sub-folder-from-one-branch-to-the-root-of-another-in-git