Git发布支持压缩提交 [英] Git Release Branch with Squashed Commits

查看:361
本文介绍了Git发布支持压缩提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做类似的事情:创建只有本地存储库历史记录子集的GitHub存储库



我现在拥有所有对主数据库的提交,现在我想要创建一个名为release的分支,它只有一次提交所有过去的提交,并且没有旧提交的历史记录。



我尝试在该链接中使用该方法,但是这样做导致任何进一步的合并到发布不自动合并,这有点烦人。 (它给出的错误是Squash提交 - 不更新HEAD,自动合并失败;修复冲突,然后提交结果。)
是否有另一种方法可以自动合并?



我知道最简单的方法是创建一个单独的回购,但理想情况下,我宁愿只使用一个分支。



我希望它看起来像这样:



v1是提交2的合并,v2是提交5的合并等。



[发布]:




  • v2

  • v1



[master]: b
$ b


  • 提交5

  • 提交4

  • 提交3
  • 提交2
  • 初始



我是新手,非常抱歉,如果这真的很明显!
Thanks!

解决方案

如果您想在发布分支中进行提交,您可以在主分支中进行顶层提交:

 #请确保我们处于发布分支
git checkout释放
#填充索引并使用顶层master树中的工作树提交
git read-tree -u --reset master
#将其提交为v1
git commit -m v1


I'm trying to do a similar thing to this: Creating GitHub repository with only a subset of a local repository's history

I currently have all my commits on master and now I want to make a branch called release that only has a single commit of all past commits and no history of the old commits.

I tried using the method in that link but doing so caused any further merges into release to not merge automatically, which is somewhat annoying. (The error it gives is Squash commit -- not updating HEAD. Automatic merge failed; fix conflicts and then commit the result.) Is there a different way of doing it that can still merge automatically?

I know the easiest method would be to create a separate repo but, ideally, I'd rather just use a branch.

I want it to end up looking something like this:

v1 is a merge from commit 2, v2 is a merge from commit 5, etc.

[release]:

  • v2
  • v1

[master]:

  • commit 5
  • commit 4
  • commit 3
  • commit 2
  • initial

I'm new to git so sorry if this is really obvious! Thanks!

解决方案

If you want to do a commit in the release branch that will have the exact same tree as the top commit in the master branch you can do:

# make sure we are on the release branch
git checkout release
# populate index and working tree with tree from top master commit 
git read-tree -u --reset master
# commit it as "v1"
git commit -m v1

这篇关于Git发布支持压缩提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆