如何将更改从主干转移到分支?
我刚刚开始使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您已签出分支 (
git checkoutbranch-name
) 并运行git rebase master
并解决出现的任何冲突。
如果您不确定这些命令的作用,请尝试不使用 TortoiseGit 并使用终端。它将帮助您真正理解命令。
警告:这假设有一个本地分支。如果您共享了分支,请不要运行变基(因为它会修改历史记录)。 运行
git merge master
当您在另一个分支上时 。这个历史记录较少,但可以使用。
区别在于:
Make sure you have your branch checked out (
git checkout branch-name
) and rungit 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:
如果您的存储库对其他人不可用,那么上面建议的 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.