获取当前的 Git 分支并“重置”分支其内容交给Master

发布于 2024-12-10 12:59:48 字数 375 浏览 0 评论 0原文

在工作中,每个开发人员都有自己的开发分支,即我们工作的开发分支。分支=员工的dev_name_of_employee。 IE。 dev_jon

dev_jon 有一个新功能,其中包含超过 100 个提交,尚未准备好进行测试或部署,因此我创建了另一个分支来将该新功能放入名为 staging_jon 的位置(可以将其称为 Holding_jon,无论如何)。

现在我需要开始另一个功能并让 dev_jon 包含 master 的内容。有点回归大师的感觉。

如何在不删除 dev_jon 及其远程分支,然后从 master 重新创建它的情况下执行此操作?我无法上演所有这些更改,因为它们已经被推动了。

或者是否有更好的方法让每个员工在开发过程中在他/她自己的一致分支上工作?

At work, each developer has his own development branch we work off of, ie. branch = dev_name_of_employee. IE. dev_jon

dev_jon has a new feature with over 100 commits in it that is not ready to be tested or deployed, so I created another branch to put that new feature in called staging_jon (could have called it holding_jon, whatever).

Now I need to start on another feature and have dev_jon contain the contents of master. Kind of a revert back to master thing.

How can I do this without deleting dev_jon and its remote branch, then recreating it from master? I cant stage all these changes because they are already pushed.

Or is there just a better way to have each employee work on his/her own consistant branch during development?

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

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

发布评论

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

评论(3

静若繁花 2024-12-17 12:59:48

在 dev_jon 中,您可以执行以下操作:

git reset --hard master

可能不直接适用/相关,但您可以查看 GitHub 流程: http://scottchacon.com/2011/08/31/github-flow.html

In dev_jon, you can do:

git reset --hard master

May not be directly applicable / relevant, but you can look at GitHub flow: http://scottchacon.com/2011/08/31/github-flow.html

难以启齿的温柔 2024-12-17 12:59:48

我认为您当前的模型并不是非常理想,开发人员应该能够同时开发多个功能,因此每个开发人员只有一个分支并不是最灵活的。无论如何,在你的情况下,假设 dev_jon 正在跟踪 origin/master,我会做什么:

git reset --hard origin/master

这也假设你当前位于 dev_jon 分支上。

希望有帮助,

I don't think your current model is really ideal, a developer should be able to develop on multiple features at the same time therefore only one branch per developer is not the most flexible. Anyway in your situation here what I would do assuming that dev_jon is tracking origin/master:

git reset --hard origin/master

This is also assuming you are currently on dev_jon branch.

Hope it helps,

时常饿 2024-12-17 12:59:48

您可以执行硬重置以使您的 dev-jon 分支与 master 分支相同,但是当您发布新作品时必须小心。远程分支 origin\dev_jon 将是您的旧功能,当您推送时,您会收到如下警告:

 ! [rejected]        dev_jon -> dev_jon (non-fast-forward)
error: failed to push some refs to '/tmp/example'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

请考虑按照 larsmans 的建议创建功能分支。

You can perform a hard reset to get your dev-jon branch to be the same as master, but you'll have to be careful when you come to publish your new work. The remote branch origin\dev_jon will be your old feature and when you come to push you'll get a warning like the following

 ! [rejected]        dev_jon -> dev_jon (non-fast-forward)
error: failed to push some refs to '/tmp/example'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

Consider creating a feature branch as suggested by larsmans.

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