my git log is like this:
commit 7cfdafdad623d2529f9c2069549619d117f4f43ec
commit afdafdafd0165af0651c1c4670bc2cd53738c2433
commit 1235cebdd758c1314ca0002a2c11f9693f43deafb
...
How can I move the most recent 2 commits to a new branch? (Note: most recent are at the top)
I am thinking
git branch newbranch
git reset --soft HEAD~1
git checkout newbranch
git commit -a
git checkout master
git reset --soft HEAD~1
git checkout newbranch
git commit -a
Is there a better way? I think my way will lost the git comments. I kind of remove the commit and re-check in.
Thank you.
You can simply issue the following two commands:
Explanation:
new_branch_namein the current (latest) commit, but don’t checkout that branch.old_branch. Next step is to point it to1235ce. This is done usingreset --hard.Now
old_branchis pointing to1235ce, andnew_branch_nameis at7cfdaf.