问题描述
我与一个使用git进行源代码管理的小团队合作。最近,我们一直在做主题分支,以跟踪功能,然后将它们合并到主机中,然后将它们推送到远程服务器上的中央git存储库。这在master中没有更改时很有用:我创建我的主题分支,提交它,将它合并到master中,然后推送。 Hooray。
但是,如果有人在我之前推送到源,我的提交并不是快进。因此合并提交随之而来。当主题分支需要本地合并以确保我的更改能够与代码一起工作时,也会发生这种情况。所以,我们最终得到了各处的合并提交以及与友谊手镯相媲美的git日志。
所以,重新定义是明显的选择。我想要的是:
我现在这样做的方式如下: p>
git checkout master
git rebase master topic_1
git rebase topic_1 topic_2
git checkout master
git rebase topic_2
git branch -d topic_1 topic_2
有没有更快捷的方式
我发现,随着时间的推移,我最喜欢的解决方案是:
git checkout主题
#make [n]提交
git rebase -i HEAD〜[n]#清理时间
git checkout master
git pull --rebase
git checkout top ic
git rebase master
git checkout master
git merge topic
git push origin
I work with a small team that uses git for source code management. Recently, we have been doing topic branches to keep track of features then merging them into master locally then pushing them to a central git repository on a remote server. This works great when no changes have been made in master: I create my topic branch, commit it, merge it into master, then push. Hooray.
However, if someone has pushed to origin before I do, my commits are not fast-forward. Thus a merge commit ensues. This also happens when a topic branch needs to merge with master locally to ensure my changes work with the code as of now. So, we end up with merge commits everywhere and a git log rivaling a friendship bracelet.
So, rebasing is the obvious choice. What I would like is to:
- create topic branches holding several commits
- checkout master and pull (fast-forward because i haven't committed to master)
- rebase topic branches onto the new head of master
- rebase topics against master(so the topics start at masters head), bringing master up to my topic head
My way of doing this currently is listed below:
git checkout master
git rebase master topic_1
git rebase topic_1 topic_2
git checkout master
git rebase topic_2
git branch -d topic_1 topic_2
Is there a faster way to do this?
I have found, over time, my favorite solution is:
git checkout topic
# make [n] commits
git rebase -i HEAD~[n] #clean up time
git checkout master
git pull --rebase
git checkout topic
git rebase master
git checkout master
git merge topic
git push origin
这篇关于git rebase到远程更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!