如何将更改从主干转移到分支?

发布于 2024-09-18 04:08:37 字数 258 浏览 10 评论 0原文

我刚刚开始使用 Git,发现当我在分支中实现某个功能时,我会遇到一些确实需要尽快推送到主干的 bug。为此,我使用 checkout 切换回主干,进行更改并提交。我现在有一个没有错误的行李箱。

不幸的是,我的分支也需要修复这个错误。由于该功能不完整,我无法将分支合并回主干。如何更改我的分支以便它接收我对主干所做的更改?

如果重要的话,我正在自己开发,因此只需担心一个存储库。

我正在使用 TortoiseGit,因此具体的说明会有所帮助,但不是必需的。

I've just started using Git and find that whilst I am implementing a feature in a branch, I will encounter some bug that really needs to be pushed to the trunk as soon as possible. In order to do so, I use checkout to switch back to the trunk, make my changes and commit them. I now have a trunk that is bug free.

Unfortunately, my branch needs to have this bug fixed as well. As the feature is not complete, I can't just merge the branch back into the trunk. How can I alter my branch so that it receives the changes I made to the trunk?

If it matters, I am developing on my own and so only have a single repository to worry about.

I am using TortoiseGit so instructions specific to that would be helpful but not necessary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

屋顶上的小猫咪 2024-09-25 04:08:38

确保您已签出分支 (git checkoutbranch-name) 并运行

git rebase master

并解决出现的任何冲突。

如果您不确定这些命令的作用,请尝试不使用 TortoiseGit 并使用终端。它将帮助您真正理解命令。

警告:这假设有一个本地分支。如果您共享了分支,请不要运行变基(因为它会修改历史记录)。 运行

git merge master

当您在另一个分支上时 。这个历史记录较少,但可以使用。

区别在于:

  • Rebase - 在 master 之上重写分支,重播所有更改
  • Merge - 正常合并,创建具有两个父级的提交

Make sure you have your branch checked out (git checkout branch-name) and run

git rebase master

And resolve any conflicts that arrive.

If you aren't sure what these commands do, try not using TortoiseGit and use the terminal. It will help you really understand the commands.

WARNING: This assumes a local branch. If you have shared the branch, do not run the rebase (because it modifies history). Run

git merge master

while you are on your other branch. This has less clean history, but can be used.

The difference is:

  • Rebase - rewrites the branch ontop of master, replaying all the changes
  • Merge - a normal merge, creating a commit with two parents
诺曦 2024-09-25 04:08:38

如果您的存储库对其他人不可用,那么上面建议的 git rebase master 就可以了。

如果您的存储库是公开可用的,那么您确实不想进行变基,因为这可能会搞砸克隆您的存储库的其他人。在这种情况下,您需要使用 git merge master 将主干中的更改合并到功能分支中。

If your repository is not available to anyone else, then git rebase master as suggested above will work.

If your repository is available publicly, you really don't want to rebase since it may screw up others who have cloned your repository. In that case, you want to use git merge master to merge the changes from trunk into your feature branch.

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