简体   繁体   English

如何将我的更改压缩到单个结果提交并选择主分支?

[英]How to squash my changes into a single result commit and pick into master branch?

Let's suppose I need to perform some average-length (several days) refactoring. 我们假设我需要执行一些平均长度(几天)的重构。

I create "mybranch" from master, do the work, sometimes I perform merges from master to mybranch (some other team members supposed to continue the work, and probably I'll need to get their changes). 我从master创建“mybranch”,完成工作,有时我执行从master到mybranch的合并(其他一些团队成员应该继续工作,可能我需要进行更改)。 And after a while I'm ready to merge my changes back to master. 过了一会儿,我准备将我的更改合并回主人。

Will I be able to squash only my changes (excluding the changesets with merges from master, since they aren't mine) and cherry-pick a single result commit of my works into the master? 我是否能够仅仅压缩我的更改 (不包括来自master的合并的更改集,因为它们不是我的)并且可以选择将我的作品的一个结果提交到master中? Is it a possible to do scenario? 可以做场景吗?

Yep. 是的。 You can confirm it with a small test repository. 您可以使用小型测试存储库进行确认。 Just do: 做就是了:

git rebase --interactive master mybranch

and choose squash for all the lines except the first. 并为除第一行以外的所有行选择squash Then you just checkout master and do a regular fast-forward merge of mybranch . 然后你只需要结帐master并定期快速合并mybranch

After rebasing, there will be no reference on those commits in previous "mybranch" 在重新定位之后,在之前的“mybranch”中将没有关于这些提交的参考

What I will do and could be more safety is that 我会做什么,可能更安全

git checkout mybranch

Create a branch (it is actually a temporary branch for rebasing purpose) 创建一个分支(它实际上是一个用于变基的临时分支)

git checkout -b movingToMaster

Try to rebase the movingTomaster to master 尝试将movingTomaster改为master

git rebase -i master

An editor will be prompted out asking you which commit should be picked, or squashed or edit... 将提示编辑器询问您应该选择哪个提交,或者压缩或编辑...

Edit that files, in your case, the first line should keep remain the same and the other line should change "pick" into "squash", you can amend your commit message if you want to. 编辑那些文件,在你的情况下,第一行应保持不变,另一行应改为“选择”为“壁球”,如果你愿意,你可以修改你的提交信息。 Save it after you make enough change on that file. 在对该文件进行足够的更改后保存它。

ie

pick 0a81405 Bug Fix 1
pick 91be655 Bug Fix 2
pick 1200fc7 Bug Fix 3
pick 1211fb7 Bug Fix 4
pick ba77fdf Bug Fix 5

Change to 改成

pick 0a81405 Bug Fix 1
squash 91be655 Bug Fix 2
squash 1200fc7 Bug Fix 3
squash 1211fb7 Bug Fix 4
squash ba77fdf Bug Fix 5

Save it. 保存。 Then 然后

git checkout master

Move your master branch to movingTomaster branch by using Fast forward merge 使用快进合并将master分支移动到movingTomaster分支

git merge movingTomaster

Note: it will be no harm since it is only a Fast-Forward Merge and would not clutter your history. 注意:它不会有害,因为它只是一个快进合并,不会使你的历史混乱。

Delete your movingTomaster branch if you want to 如果您愿意,请删除您的movingTomaster分支

git branch -D movingTomaster

暂无
暂无

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

相关问题 在主分支中压缩提交消息 - Squash commit message in master branch 如何使用 SmartGIT 在一次提交中压缩合并从分支到主控的多个提交? - How to squash merge multiple commits from branch to master in a single commit using SmartGIT? 在单个提交中将多个非顺序提交从远程分支更改为“主”分支 - cherry-pick changes of multiple non sequential commits from remote branches to “master” branch in single commit 合并(使用壁球)来自另一个分支的所有更改作为单个提交 - Merge (with squash) all changes from another branch as a single commit 如何在一个git commit中将master分支的更改合并到我的side project分支中? - How do I merge a master branch's changes into my side project branch in one git commit? 从 Master 到 Branch(Master 提交 --> Branch),cherry-pick 是否有效? - Is cherry-pick works from Master to Branch (Master commit --> Branch)? Git:压缩功能分支和合并提交,基于 master - Git: Squash feature branch and merge commit, rebase on master 压榨master分支的历史记录,但将所有先前的提交消息归咎于此? - Squash master branch history but keep all prior commit messages in blame? 从master合并后的Squash功能分支提交 - Squash feature branch commit after merging from master 在一次提交更改时,如何使我的分支像另一个分支一样? - How do I make my branch like another branch while making the changes as a single commit?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM