Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
git复制一个提交到新分支_Git - Fatal编程技术网

git复制一个提交到新分支

git复制一个提交到新分支,git,Git,我想创建一个新分支,其中只包含一个特定提交的副本(来自master,即)。我该怎么做 我最接近这一点的是: git checkout --orphan NEWBRANCH git rm -rf . git commit "MESSAGE MESSAGE MESSAGE" git cherry-pick -x <hash> git签出——孤儿纽伯兰 吉特rm-rf。 git提交“消息” git cherry pick-x 基本上,我希望上面没有“消息”提交 我在cherry pic

我想创建一个新分支,其中只包含一个特定提交的副本(来自master,即)。我该怎么做

我最接近这一点的是:

git checkout --orphan NEWBRANCH
git rm -rf .
git commit "MESSAGE MESSAGE MESSAGE"
git cherry-pick -x <hash>
git签出——孤儿纽伯兰
吉特rm-rf。
git提交“消息”
git cherry pick-x
基本上,我希望上面没有“消息”提交

我在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'
$git樱桃镐-x 68cc6733a14ec571c0abb0d4e77f53d93446f009
错误:无法应用68cc673。。。asdvasdflmdamfvla
提示:解决冲突后,标记更正的路径
提示:使用“git add”或“git rm”
提示:并使用“git commit”提交结果
用法

copy_as_root_commit <commitid> <new_branch>
copy_as_root_commit master~4 NEW_ROOT

copy_as_root_commit ce04aa6 NEWBRANCH

问题不清楚。您想创建一个新分支,它以一个空存储库开始,然后cherry选择一个提交?或者您想在特定提交(包括其所有历史记录)时启动一个新分支?还是别的?在新的分支中,我只希望有一个提交,没有历史记录。这种方式的可能重复不会留下它来自哪个提交的痕迹。另一种方法是使用
cherry pick-x
解决此问题。@KcFnMi和
git cherry pick-x
到源提交的唯一连接是通过提交消息。没有什么可以阻止您将这些信息放入提交消息中,例如,
git commit-a-m“commit的副本”
我认为
git cherry pick-x
是自动的:)@KcFnMi如果您需要定期执行此操作,那么也可以通过一个简单的脚本使其自动。这很酷。在答案上有更多的细节会很有趣。
copy_as_root_commit master~4 NEW_ROOT

copy_as_root_commit ce04aa6 NEWBRANCH