Git Release Branch with Squashed Commits

帅比萌擦擦* 提交于 2019-12-10 00:23:46

问题


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!


回答1:


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


来源:https://stackoverflow.com/questions/10769389/git-release-branch-with-squashed-commits

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