KcFnMi KcFnMi - 2 months ago 24
Git Question

git copy one commit to new branch

I would like to create a new branch with a copy of one particular commit only (from master, i.e.). How do I do that?

The closest I got to that is something like:

git checkout --orphan NEWBRANCH
git rm -rf .
git commit "MESSAGE MESSAGE MESSAGE"
git cherry-pick -x <hash>


Basically, I would like the above without the "MESSAGE MESSAGE MESSAGE" commit.

I got an error after cherry-pick:

$ git cherry-pick -x 68cc6733a14ec571c0abb0d4e77f53d93446f009
error: could not apply 68cc673... asdvasdflmdamfvla
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'

Answer
git checkout --orphan NEWBRANCH <commitid>
git commit -a

git checkout --orphan <new_branch> [<start_point>]

Create a new orphan branch, named <new_branch>, started from <start_point> and switch to it. The first commit made on this new branch will have no parents and it will be the root of a new history totally disconnected from all the other branches and commits.

The index and the working tree are adjusted as if you had previously run "git checkout <start_point>". This allows you to start a new history that records a set of paths similar to <start_point> by easily running "git commit -a" to make the root commit.

Comments