简体   繁体   English

如何将更改从功能分支合并到主分支

[英]How to merge changes from feature branch to main branch

A lot of work was done on a feature branch, and during this time, there were multiple commits on the branch but also merge commits with changes from the main branch. 在功能分支上完成了大量工作,在此期间,分支上有多个提交,但也将提交与主分支的更改合并。

Now the feature branch has commits like this: 现在功能分支有这样的提交:

  • Work 6 (done on the feature branch) 工作6(在功能部门完成)
  • Work 5 (done on the feature branch) 工作5(在功能部门完成)
  • Work D (done on the main branch) 工作D(在主要分支上完成)
  • Work C (done on the main branch) 工作C(在主要分支上完成)
  • Merge branch 'main' into 'feature' 分支'main' 合并为'feature'
  • Work 3 (done on the feature branch) 工作3(在功能部门完成)
  • Work B (done on the main branch) 工作B(在主要分支上完成)
  • Work A (done on the main branch) 工作A(在主要分支上完成)
  • Merge branch 'main' into 'feature' 分支'main' 合并为'feature'
  • Work 2 (done on the feature branch) 工作2(在功能部门完成)
  • Work 1 (done on the feature branch) 工作1(在功能部门完成)

Now there is a pull request created on the GitHub repo, but it's hard to follow through the all the changes and approve it. 现在在GitHub仓库上创建了拉取请求,但是很难完成所有更改并批准它。

What I would like is to squash commits made on the feature branch, such that I will have just one nice commit which I need to review. 我想要的是压缩功能分支上的提交,这样我只需要一个很好的提交,我需要审查。

How can I do that? 我怎样才能做到这一点?

I've read about squashing changes and rebasing, but I need some help. 我已经阅读过关于压制变化和变基的文章,但我需要一些帮助。 Can I just call rebase -i [commitnumber] where commit number is of Work 1 ? 我可以调用rebase -i [commitnumber] ,其中commit number是Work 1吗? I used this on feature branches and it worked great but not when merge commits exist. 我在功能分支上使用了它,它工作得很好但不存在合并提交时。

Use git merge --squash 使用git merge --squash

That's the simplest way. 这是最简单的方法。 Go to your main branch and merge the feature branch using the --squash option. 转到main分支并使用--squash选项合并feature分支。

git checkout main
git merge --squash feature

Use git rebase -i 使用git rebase -i

This would be what you suggested. 这就是你的建议。 Before rebasing make sure you have a backup copy of your feature branch. 在变基之前,请确保您拥有功能分支的备份副本。 On your feature branch invoke git branch : 在您的功能分支上调用git branch

git checkout feature
git branch feature_backup

Now check the log for the SHA hash of the commit where the development of your feature has started. 现在检查日志中是否已开始开发功能的提交的SHA哈希。 If this was a long time ago, you can use this command to see where the feature branch splitted from the main branch: 如果这是很久以前的事了,您可以使用此命令查看feature分支从main分支中分割的位置:

git merge-base main feature

Then use git rebase : 然后使用git rebase

git rebase bc4b30e

Proceed like it is described here . 继续像这里描述的那样 You're not supposed to give the number of commits you want to squash but to give the SHA hash of the first commit you want to squash. 您不应该提供您想要压缩的提交数量,而是要提供您要压缩的第一个提交的SHA哈希值。 You can use HEAD~n if that was n commits ago. 你可以使用HEAD~n如果那是n提交前。

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

相关问题 如何将分支“ Main”的更改同步到从分支“ Main”创建的分支“ Feature01” - How to sync changes of branch “Main” to branch “Feature01” which created from branch “Main” 合并/还原失败后将更改从主分支带到功能分支 - Bring Changes from Main branch to feature branch after failed merge/revert 如何正确地将多个功能合并到主分支 - how to correctly merge several feature to main branch 获取从主分支到功能分支的更改而不合并任何内容 - Get changes from main branch to feature branch without merging anything 如何将更改与开发分支合并到功能分支 - How to merge changes with develop branch down to a feature branch 如何撤消功能分支中对主线的更改,但保持分支更新? - How do you undo changes committed to main line from a feature branch but keep the branch up to date? 如何在不添加孤儿历史的情况下将合并更改从主分支到孤立分支? - How to git merge changes from main branch to orphan branch without adding to orphan's history? 如何从 master 的另一个功能分支 rebase 或合并分支 - How to rebase or merge a branch from another feature branch from master 如何将 6 个提交更改为 2 个从功能分支到主分支 - How to change 6 commits into 2 from feature branch to main branch 如何将最新的更改从主分支转换为功能分支? - How to get latest changes from master branch into feature branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM