Git 子树工作流程

发布于 2024-11-17 00:10:42 字数 731 浏览 3 评论 0原文

在我当前的项目中,我使用开源论坛( 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌化 2024-11-24 00:10:42

我完成了这个方案:

  1. 处理我的开发分支,接触子树中的文件。

  2. 使用压缩的开发提交更新子树分支:

    <块引用>

    git merge -s subtree --squash --no-commit 开发

  3. 使用其远程存储库更新 subtree 分支。

  4. 使用压缩的子树提交更新开发

    <块引用>

    git merge --squash -s 子树 --no-commit 子树

I finished up with this scheme:

  1. Work on my development branch touching files from the subtree.

  2. Update the subtree branch with squashed development commits:

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

  3. Update the subtree branch with its remote repository.

  4. Update development with squashed subtree commits:

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

赠我空喜 2024-11-24 00:10:42

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.

北方的巷 2024-11-24 00:10:42

使用

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

不会“覆盖”您的更改。我希望“更新提交”指的是子树合并后所做的提交,因为它具有 --no-commit 并且不会自行提交。

Using

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

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.

小姐丶请自重 2024-11-24 00:10:42

我也不是 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文