简体   繁体   English

拿一个当前的Git分支并将其内容“重置”给Master

[英]Take a Current Git Branch and “reset” Its contents to Master

At work, each developer has his own development branch we work off of, ie. 在工作中,每个开发人员都有自己的开发分支,即。 branch = dev_name_of_employee. branch = dev_name_of_employee。 IE. IE浏览器。 dev_jon 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). dev_jon有一个新功能,其中有超过100个提交,尚未准备好进行测试或部署,因此我创建了另一个分支,将该新功能放入名为staging_jon(可以称之为holding_jon,无论如何)。

Now I need to start on another feature and have dev_jon contain the contents of master. 现在我需要从另一个功能开始并让dev_jon包含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? 如何在不删除dev_jon及其远程分支的情况下执行此操作,然后从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? 或者,在开发过程中,是否有更好的方法让每个员工在他/她自己的一致分支上工作?

In dev_jon, you can do: 在dev_jon中,您可以:

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 可能不是直接适用/相关,但您可以查看GitHub流程: http//scottchacon.com/2011/08/31/github-flow.html

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: 无论如何,在你的情况下,假设dev_jon正在跟踪origin / master,我会做什么:

git reset --hard origin/master

This is also assuming you are currently on dev_jon branch. 这也假设您当前在dev_jon分支上。

Hope it helps, 希望能帮助到你,

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. 您可以执行硬重置以使您的dev-jon分支与master相同,但是当您发布新工作时,您必须要小心。 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 远程分支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.

Consider creating a feature branch as suggested by larsmans. 考虑按照larsmans的建议创建一个功能分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM