如何推/拉 Git rebase

发布于 2024-08-20 09:59:06 字数 928 浏览 6 评论 0原文

我想使用 git rebase 来干净地合并 master 分支中的功能(减少提交或至少在更改日志的顶部)。请注意,我是唯一一个在存储库上工作的人

阅读 Git 工作流程和 rebase 与合并问题后,我发现 git rebase 会非常好,就像 Micah 一样,我想 git Push 重新调整更改的基础,只是因为我正在从不同的地方处理它们(例如:我的笔记本,我的家,某处的另一台电脑...)

所以这里有两个解决方案(双向丑陋的合并):

  1. 使用 git push -f 推送,然后在其他机器上拉取,但是如何在其他机器上干净地获取最新版本呢?
  2. 使用 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):

  1. Using git push -f to push, and then pulling on other machine, but how to cleanly get the latest version on other machines?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2024-08-27 09:59:06

我总是确保我从我离开的任何机器上提交并推送(-f)所有内容。

当我到达其他机器时:

 git fetch -v
 git checkout mybranch # Already checked out with old HEAD
 git reset --hard origin/mybranch

这很有效,因为我知道不同计算机上的另一个“我”在我离开之前一致地提交和推送(因此我到达的机器上没有未推送的更改)

I always make sure I commit and push (-f) everything from any machine I leave.

When I arrive at some other machine:

 git fetch -v
 git checkout mybranch # Already checked out with old HEAD
 git reset --hard origin/mybranch

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)

烟火散人牵绊 2024-08-27 09:59:06

请记住,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 the git rebase documentation begins (with added emphasis):

Rebasing (or any other form of rewriting) a branch that others have based work on is a bad idea: anyone downstream of it is forced to manually fix their history. This section explains how to do the fix from the downstream's point of view. The real fix, however, would be to avoid rebasing the upstream in the first place.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文