简体   繁体   中英

Git - how to move last X commits on master to a feature branch?

Let's say I'm on master (at C4), and stuff is broken but it was working back at commit C1. How can I effectively copy all commits up to C4 to a new branch to preserve the unstable code, and then roll master back to C1? (this is so I can push it to GitHub and have continuous deployment push master code to the live server)

I know the first step is to branch the feature off of master as is, but then how do I roll back master to commit C1?

git checkout -b holdingBranch

This will create a new branch based on the current master. Then you can roll back on master with

git checkout master
git reset --hard C1

without affecting the new branch and successfully rolling back master

$git checkout master
$git branch testing
$git checkout master
$git reset --hard hash_of_your_C1(like de79f21269b02125e50cf788fa83e91)
$git push origin master 

That should works, you can always check your testing development with

$git checkout testing

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