如何推/拉 Git rebase
我想使用 git rebase 来干净地合并 master 分支中的功能(减少提交或至少在更改日志的顶部)。请注意,我是唯一一个在存储库上工作的人。
阅读 Git 工作流程和 rebase 与合并问题后,我发现 git rebase
会非常好,就像 Micah 一样,我想 git Push
重新调整更改的基础,只是因为我正在从不同的地方处理它们(例如:我的笔记本,我的家,某处的另一台电脑...)
所以这里有两个解决方案(双向丑陋的合并):
- 使用 git push -f 推送,然后在其他机器上拉取,但是如何在其他机器上干净地获取最新版本呢?
- 使用 merge 将主更改合并到功能分支,git 推/拉,一旦成熟,就进行一次变基(干净地在一个或多个提交中)
(2)如下所示:
git co -b feature-a
... change files
git push origin feature-a
... moving to another PC
git pull origin feature-a
... change files
git merge master
... change files (not the "special rebase")
git rebase master
git co master
git merge feature-a
git branch -d feature-a
git push origin :feature-a
您认为哪种解决方案可行?到目前为止我还没有尝试过其中任何一个(主要是担心让我的日志更加混乱)。
I'd like to use git rebase
so as to cleanly merge a feature in the master branch (in less commits or at least at the top of the change log). Note that I'm the only one working on the repository.
After reading Git workflow and rebase vs merge questions, I found git rebase
would be pretty nice and like Micah I'd like to git push
rebased changes simply because I'm working on them from different places (ex: my notebook, my home, another PC somewhere...)
So here are two solutions (to the bi-directional ugly merge):
- Using
git push -f
to push, and then pulling on other machine, but how to cleanly get the latest version on other machines? - Using merge to merge master changes to the feature branch, git push/pull, and once mature, do a single rebase (in one or more commits cleanly)
(2) would be like below:
git co -b feature-a
... change files
git push origin feature-a
... moving to another PC
git pull origin feature-a
... change files
git merge master
... change files (not the "special rebase")
git rebase master
git co master
git merge feature-a
git branch -d feature-a
git push origin :feature-a
Which solution do you think would work? I haven't tried either of them so far (mostly by fear of making my log more messy).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我总是确保我从我离开的任何机器上提交并推送(-f)所有内容。
当我到达其他机器时:
这很有效,因为我知道不同计算机上的另一个“我”在我离开之前一致地提交和推送(因此我到达的机器上没有未推送的更改)
I always make sure I commit and push (-f) everything from any machine I leave.
When I arrive at some other machine:
This works well because I know the other "me" at different computers consistently commits and pushes before I leave (And therefore there are no unpushed changes on the machine I arrive at)
请记住,
git rebase
会重播更改并创建新的提交。通过在各处重新设置基础并强制推动,您将违背工具的原则。请注意“从上游变基恢复”git rebase 文档的 > 部分开始(特别强调):即使您是唯一的开发人员,在工作时您仍然是其他人(从一个存储库的角度来看)在其他克隆中。正如您所看到的,这个工作流程很麻烦。
让你的改变在分支中进行。当一个分支准备好进入黄金时段时,然后变基,将其合并到 master 中,并删除其主题分支。如果你缩短分支的生命周期并缩小它们的范围,你的生活将会变得最轻松。
Remember that
git rebase
replays changes and creates new commits. By rebasing and forcing pushes all over the place, you're going against the grain of the tool. Note how the "Recovering from an upstream rebase" section of thegit rebase
documentation begins (with added emphasis):Even though you're the sole developer, you'll still be others (from the perspective of one repo) when working in other clones. As you've seen, this workflow is a hassle.
Let your changes cook in branches. When a branch is ready for primetime, then rebase, merge it into master, and delete its topic branch. Your life will be easiest if you keep branches' lifetimes short and their scopes narrow.