简体   繁体   English

如何使用来自开放 PR 的压缩提交来启动一个新分支?

[英]How can I start a new branch with squashed commits from an open PR?

The problem: I have a PR with a tonne of commits.问题:我有一个提交大量提交的 PR。 The branch name is also not accurate.分支名称也不准确。 I would like to start a new branch, and continue from the latest commit, without cherry picking each commit.我想开始一个新的分支,并从最新的提交继续,而不是挑选每个提交。 I want all the work to be reduced to 1 commit that reflects its latest state.我希望将所有工作减少到 1 次提交,以反映其最新的 state。

I first tried rebasing, but the commits conflict with each other.我第一次尝试变基,但提交相互冲突。

I then thought about cherry picking just the latest commit but I'm unsure of the syntax.然后我考虑只挑选最新的提交,但我不确定语法。 (yes i read the docs but its not clear to me still). (是的,我阅读了文档,但我仍然不清楚)。

I have checked out a new branch:我检查了一个新分支:

git checkout -b <new-branch>

then I tried:然后我尝试了:

git cherry pick <commit-sha> <branch-name>

The branch I want to 'correct' is an open PR.我想“纠正”的分支是一个开放的 PR。

This doesn't work as the terminal says "Unknown commit pick".这不起作用,因为终端显示“未知提交选择”。

Can anyone help me out?谁能帮我吗?

I have a PR with a tonne of commits.我有一个有大量提交的 PR。 The branch name is also not accurate.分支名称也不准确。 I would like to start a new branch, and continue from the latest commit, without cherry picking each commit.我想开始一个新的分支,并从最新的提交继续,而不是挑选每个提交。 I want all the work to be reduced to 1 commit that reflects its latest state.我希望将所有工作减少到 1 次提交,以反映其最新的 state。

  1. Checkout your old branch.检查你的旧分支。

  2. Make a new branch and get on to it.创建一个新分支并继续它。

  3. reset --soft to the first commit of the old branch (possibly even the commit that you branched "from") and make a commit. reset --soft为旧分支的第一次提交(甚至可能是您“从”分支的提交)并进行提交。

Now your new branch "consists" of just that one commit, embodying the whole history of the old branch.现在,您的新分支“仅包含”一个提交,体现了旧分支的全部历史。 Keep working.继续工作。 (You can withdraw the PR and delete the old branch if you like.) (如果您愿意,可以撤回 PR 并删除旧分支。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PR 用于从被压扁和合并的前一个分支创建的分支显示前一个分支的提交 - PR for branch made from previous branch that was squashed and merged shows previous branch's commits 如何将多个提交合并到另一个分支作为单个压缩提交? - How can I merge multiple commits onto another branch as a single squashed commit? 当我压缩来自父分支的提交并将其合并到主分支时,子分支会发生什么? - What happens to the child branch when I have squashed the commits from parent branch and merged it into master? 如何确定哪些提交被git压缩? - How can I determine which commits were squashed in git? 如何从 PR 的另一个分支中删除不需要的提交 - How do I remove unwanted commits form another branch for PR 我可以在合并之前通过提交创建新分支 - Can I create new branch from commits prior to merge 如何将我的2个提交移动到新分支? - How can I move 2 of my commits to a new branch? 如何将几个 Git 提交回滚到新分支? - How can I roll back several Git commits into new branch? 如何在git中将我的十个提交从master转移到一个新的分支? - How can I move my ten commits from master to a new branch in git? 如何从合并和还原的PR到新的PR中获得提交? - How do I get commits from a merged and reverted PR into a new one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM