Git 将除第一个以外的所有提交推送到远程仓库
Git push all commits except first to a remote repo
我要实现的是将除第一个(初始代码库)之外的所有提交(我的更改)推送到 public 存储库。
A - B - C - D - E
我只想推送到一个新的远程仓库
B-C-D-E
可以吗?
如果您希望项目 content 的第一次修订是 B 中的内容,您可以这样做:
git checkout --orphan new-branch B
git commit -m "new first revision" # use a proper comment
git cherry-pick B..E # replicate revisions C, D and E
那么new-branch
就有你期待的历史了
如果您尝试使用交互式 rebase 删除第一个修订版,预计会在来自 A 的 B 上修改的所有文件上发生冲突。比如说,如果 A 布置了所有或大部分文件,那么无论如何被 B 修改 的文件会发生冲突(应用 C、D 和 E 时可能会出现其他冲突),因为当 git 将尝试修改时文件不存在在 rebase 上应用 B……无论如何,这不是最难解决的事情……但我提供的方法完全跳过了这个问题。
PS
另一种可以通过交互式变基来完成的方法是 运行:
git rebase -i --root
# revision A, the first one, leave it with a pick
# but ask to squash the second one B
# C, D and E, leave them with a pick
# save and exit
# git will stop so you can set the comment that will be left on the first revision,
# if I'm not wrong, and will show you the first and second revision comment
# set the right comment, save and exit
# rebase will continue and you will get a branch like what you are asking for
PS2 所以我认为要求与问题推断的内容略有不同(阅读对此答案的评论)。
git checkout -b --orphan new-branch A
git rm -r * # remove everyhing
git show --summary --pretty= --name-only B | xargs git checkout B --
# that should get back only the files that were modified in B
git commit -m "whatever comment"
git cherry-pick B..E
应该可行
我要实现的是将除第一个(初始代码库)之外的所有提交(我的更改)推送到 public 存储库。
A - B - C - D - E
我只想推送到一个新的远程仓库
B-C-D-E
可以吗?
如果您希望项目 content 的第一次修订是 B 中的内容,您可以这样做:
git checkout --orphan new-branch B
git commit -m "new first revision" # use a proper comment
git cherry-pick B..E # replicate revisions C, D and E
那么new-branch
就有你期待的历史了
如果您尝试使用交互式 rebase 删除第一个修订版,预计会在来自 A 的 B 上修改的所有文件上发生冲突。比如说,如果 A 布置了所有或大部分文件,那么无论如何被 B 修改 的文件会发生冲突(应用 C、D 和 E 时可能会出现其他冲突),因为当 git 将尝试修改时文件不存在在 rebase 上应用 B……无论如何,这不是最难解决的事情……但我提供的方法完全跳过了这个问题。
PS
另一种可以通过交互式变基来完成的方法是 运行:
git rebase -i --root
# revision A, the first one, leave it with a pick
# but ask to squash the second one B
# C, D and E, leave them with a pick
# save and exit
# git will stop so you can set the comment that will be left on the first revision,
# if I'm not wrong, and will show you the first and second revision comment
# set the right comment, save and exit
# rebase will continue and you will get a branch like what you are asking for
PS2 所以我认为要求与问题推断的内容略有不同(阅读对此答案的评论)。
git checkout -b --orphan new-branch A
git rm -r * # remove everyhing
git show --summary --pretty= --name-only B | xargs git checkout B --
# that should get back only the files that were modified in B
git commit -m "whatever comment"
git cherry-pick B..E
应该可行