Git 子树工作流程
在我当前的项目中,我使用开源论坛( https://github.com/vanillaforums/Garden ).我打算做这样的事情:
git remote add vanilla_remote https://github.com/vanillaforums/Garden.git
git checkout -b vanilla vanilla_remote/master
git checkout master
git read-tree --prefix=vanilla -u vanilla
这样我可以对 vanilla 文件夹进行更改(例如更改配置)并将其提交到我的 master 分支,我也可以切换到我的 vanilla 分支来获取更新。我的问题是当我尝试将分支合并在一起时
git checkout vanilla
git pull
git checkout master
git merge --squash -s subtree --no-commit vanilla
git commit -a -m "update commit"
问题是“更新提交”位于我的提交之上并“覆盖”我的更改。我宁愿让我的提交在更新之上重放。有没有一种简单的方法可以做到这一点?我不太擅长 git 所以也许这是错误的方法。另外,我真的不想把我的历史和普通的历史混在一起。
In my current project I'm using an open source forum ( https://github.com/vanillaforums/Garden ). I was planning on doing something like this :
git remote add vanilla_remote https://github.com/vanillaforums/Garden.git
git checkout -b vanilla vanilla_remote/master
git checkout master
git read-tree --prefix=vanilla -u vanilla
This way I can make change into the vanilla folder (like changing config) and commit it to my master branch and I can also switch into my vanilla branch to fetch updates. My problem is when I try to merge the branch together
git checkout vanilla
git pull
git checkout master
git merge --squash -s subtree --no-commit vanilla
git commit -a -m "update commit"
The problem is that the "update commit" goes on top of my commits and "overwrite" my change. I would rather like to have my commits replay on top of the update. Is there a simple way to do that? I'm not very good in git so maybe this is the wrong approach. Also, I really don't want to mix my history with the vanilla history.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我完成了这个方案:
处理我的开发分支,接触子树中的文件。
使用压缩的开发提交更新子树分支:
<块引用>
git merge -s subtree --squash --no-commit 开发
使用其远程存储库更新 subtree 分支。
<块引用>
git merge --squash -s 子树 --no-commit 子树
I finished up with this scheme:
Work on my development branch touching files from the subtree.
Update the subtree branch with squashed development commits:
Update the subtree branch with its remote repository.
如果您希望使用子树,您可能需要使用
git subtree
< /a>.它为这类事情提供了一个更加用户友好的界面,包括合并/拉取命令以合并到子树中(挤压是可选的)和分割/推送命令以将更改拆分为子树并将它们发送回自己的子树回购。If you're looking to work with subtrees, you probably want to use
git subtree
. It provides a somewhat more user-friendly interface to this sort of thing, including merge/pull commands to merge in a subtree (squashing is optional) and split/push commands to split back apart changes to a subtree and send them back to its own repo.使用
不会“覆盖”您的更改。我希望“更新提交”指的是子树合并后所做的提交,因为它具有
--no-commit
并且不会自行提交。Using
will not "overwrite" your change. I am hoping by "update commit" you mean the commit you did after the subtree merge since it has
--no-commit
and will not commit by itself.我也不是 git 大师(看看我在那里做了什么;-))...但是,我想你可能想看看 rebase 命令:
http://book.git-scm.com/4_rebasing.html
I too am not a git master (see what I did there ;-) ) ... however, I think you may want to look at the rebase command:
http://book.git-scm.com/4_rebasing.html