我想创建一个新分支,只包含一个特定提交的副本(来自主,即)。我该怎么做?
我最接近的是:
git checkout --orphan NEWBRANCH
git rm -rf .
git commit "MESSAGE MESSAGE MESSAGE"
git cherry-pick -x <hash>基本上,我希望上面没有“消息”提交。
我在采樱桃后出了个差错:
$ 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'发布于 2016-09-23 15:23:23
git checkout --orphan NEWBRANCH <commitid>
git commit -a
git checkout --orphan <new_branch> [<start_point>]创建一个名为<new_branch>的新孤儿分支,从<start_point>开始并切换到它。在这个新分支上进行的第一次提交将没有父级,它将是一个与所有其他分支完全断开并提交的新历史的根源。 索引和工作树被调整,就像以前运行"git checkout <start_point>“一样。这允许您启动一个新的历史记录,通过轻松地运行"git commit -a“来进行根提交,从而记录一组类似于git commit -a的路径。
编辑
下面的脚本将一次性完成此工作(请注意,为了消除可能的失败原因,它需要从未跟踪的文件中清除工作树,但它将请求允许这样做):
copy_as_root_commit
#!/bin/sh
myname="$(basename "$0")"
if [ $# -ne 2 ]
then
echo 1>&2 "Usage: $myname <commitid> <new_branch>"
exit 1
fi
commitid=$(git rev-parse "$1")
new_branch="$2"
set -e
untracked_stuff="$(git clean -dxf -n)"
if [ "$untracked_stuff" ]
then
echo "$myname needs to clean the working tree before proceeding:"
printf "%s\n" "$untracked_stuff"
while read -p "Remove above files? (y/n) " answer
do
case "$answer" in
[yY]) break ;;
[nN]) exit 1 ;;
esac
done
fi
git clean -dxf \
&& git checkout --orphan "$new_branch" "$commitid" \
&& git commit -m "Initial commit (a copy of $commitid)" \
&& echo "Successfully created new root branch '$new_branch'" \
|| echo "Failed to create new root branch '$new_branch'"使用
copy_as_root_commit <commitid> <new_branch>示例
copy_as_root_commit master~4 NEW_ROOT
copy_as_root_commit ce04aa6 NEWBRANCHhttps://stackoverflow.com/questions/39662227
复制相似问题