[英]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.