简体   繁体   中英

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. 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?

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

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,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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